Skip to content

Commit c6c7c92

Browse files
committed
2.0.56.android4 release
1 parent 50079d5 commit c6c7c92

23 files changed

+490
-32
lines changed

benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.55.android5</version>
9+
<version>2.0.56.android5</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

codegen-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.55.android5</version>
9+
<version>2.0.56.android5</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.55.android5</version>
9+
<version>2.0.56.android5</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

core/src/main/java/com/alibaba/fastjson2/JSON.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface JSON {
3232
/**
3333
* fastjson2 version name
3434
*/
35-
String VERSION = "2.0.55";
35+
String VERSION = "2.0.56";
3636

3737
/**
3838
* Parses the json string as a {@link JSONArray} or {@link JSONObject}.

core/src/main/java/com/alibaba/fastjson2/JSONReader.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,7 @@ public void config(Feature feature, boolean state) {
37943794
}
37953795
}
37963796
}
3797+
protected static final long MASK_DISABLE_REFERENCE_DETECT = 1L << 33;
37973798

37983799
public enum Feature {
37993800
FieldBased(1),
@@ -3917,7 +3918,12 @@ public enum Feature {
39173918
/**
39183919
* @since 2.0.53
39193920
*/
3920-
UseDoubleForDecimals(1L << 32L);
3921+
UseDoubleForDecimals(1L << 32L),
3922+
3923+
/**
3924+
* @since 2.0.56
3925+
*/
3926+
DisableReferenceDetect(MASK_DISABLE_REFERENCE_DETECT);
39213927

39223928
public final long mask;
39233929

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ public byte[] readHex() {
154154
return bytes;
155155
}
156156

157-
@Override
158157
public final boolean isReference() {
158+
if ((context.features & MASK_DISABLE_REFERENCE_DETECT) != 0) {
159+
return false;
160+
}
159161
// should be codeSize <= FreqInlineSize 325, current is 276
160162
final char[] chars = this.chars;
161163
char ch = this.ch;
@@ -188,6 +190,11 @@ public final boolean isReference() {
188190
return false;
189191
}
190192

193+
return isReference0(chars, offset, end, quote);
194+
}
195+
196+
private boolean isReference0(char[] chars, int offset, int end, char quote) {
197+
char ch;
191198
offset += 6;
192199
ch = chars[offset];
193200
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
@@ -211,7 +218,9 @@ public final boolean isReference() {
211218
ch = chars[offset];
212219
}
213220

214-
if (ch != quote || (offset + 1 < end && chars[offset + 1] == '#')) {
221+
if (ch != quote
222+
|| (offset + 1 < end && (ch = chars[offset + 1]) != '$' && ch != '.' && ch != '@')
223+
) {
215224
return false;
216225
}
217226

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
class JSONReaderUTF8
1818
extends JSONReader {
19+
static final int REF = BIG_ENDIAN ? 0x24726566 : 0x66657224;
20+
1921
protected final byte[] bytes;
2022
protected final int length;
2123
protected final int start;
@@ -4683,8 +4685,11 @@ public final byte[] readHex() {
46834685
}
46844686

46854687
@Override
4686-
public boolean isReference() {
4688+
public final boolean isReference() {
46874689
// should be codeSize <= FreqInlineSize 325, current : 284
4690+
if ((context.features & MASK_DISABLE_REFERENCE_DETECT) != 0) {
4691+
return false;
4692+
}
46884693
final byte[] bytes = this.bytes;
46894694
int ch = this.ch;
46904695
if (ch != '{') {
@@ -4705,17 +4710,18 @@ public boolean isReference() {
47054710
ch = bytes[offset];
47064711
}
47074712

4708-
int quote = ch;
47094713
if (offset + 6 >= end
4710-
|| bytes[offset + 1] != '$'
4711-
|| bytes[offset + 2] != 'r'
4712-
|| bytes[offset + 3] != 'e'
4713-
|| bytes[offset + 4] != 'f'
4714-
|| bytes[offset + 5] != quote
4714+
|| bytes[offset + 5] != ch
4715+
|| UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset + 1) != REF
47154716
) {
47164717
return false;
47174718
}
47184719

4720+
return isReference0(bytes, offset, end, ch);
4721+
}
4722+
4723+
private boolean isReference0(byte[] bytes, int offset, int end, int quote) {
4724+
int ch;
47194725
offset += 6;
47204726
ch = bytes[offset];
47214727
while (ch >= 0 && ch <= ' ' && ((1L << ch) & SPACE) != 0) {
@@ -4739,7 +4745,9 @@ public boolean isReference() {
47394745
ch = bytes[offset];
47404746
}
47414747

4742-
if (ch != quote || (offset + 1 < end && bytes[offset + 1] == '#')) {
4748+
if (ch != quote
4749+
|| (offset + 1 < end && (ch = bytes[offset + 1]) != '$' && ch != '.' && ch != '@')
4750+
) {
47434751
return false;
47444752
}
47454753

core/src/main/java/com/alibaba/fastjson2/annotation/JSONField.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,9 @@
121121
* @since 2.0.52
122122
*/
123123
Class<?> arrayToMapDuplicateHandler() default Void.class;
124+
125+
/**
126+
* @since 2.0.56
127+
*/
128+
Class<?> contentAs() default Void.class;
124129
}

core/src/main/java/com/alibaba/fastjson2/codec/FieldInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class FieldInfo {
2020
public static final long DISABLE_REFERENCE_DETECT = 1L << 58;
2121
public static final long BACKR_EFERENCE = 1L << 61;
2222
public static final long RECORD = 1L << 62;
23+
public static final long CONTENT_AS = 1L << 63;
2324

2425
public String fieldName;
2526
public String format;
@@ -44,6 +45,11 @@ public class FieldInfo {
4445
public String arrayToMapKey;
4546
public Class<?> arrayToMapDuplicateHandler;
4647

48+
/**
49+
* @since 2.0.56
50+
*/
51+
public Class<?> contentAs;
52+
4753
public ObjectReader getInitReader() {
4854
Class<?> calzz = readUsing;
4955
if (calzz != null && ObjectReader.class.isAssignableFrom(calzz)) {
@@ -94,5 +100,6 @@ public void init() {
94100

95101
arrayToMapKey = null;
96102
arrayToMapDuplicateHandler = null;
103+
contentAs = null;
97104
}
98105
}

core/src/main/java/com/alibaba/fastjson2/writer/FieldWriterList.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ abstract class FieldWriterList<T>
2121
ObjectWriter listWriter;
2222
ObjectWriter itemObjectWriter;
2323
final boolean writeAsString;
24+
final Class<?> contentAs;
2425

2526
FieldWriterList(
2627
String name,
@@ -32,9 +33,11 @@ abstract class FieldWriterList<T>
3233
Type fieldType,
3334
Class fieldClass,
3435
Field field,
35-
Method method
36+
Method method,
37+
Class<?> contentAs
3638
) {
3739
super(name, ordinal, features, format, label, fieldType, fieldClass, field, method);
40+
this.contentAs = contentAs;
3841

3942
writeAsString = (features & WriteNonStringValueAsString.mask) != 0;
4043

@@ -74,6 +77,13 @@ public Class getItemClass() {
7477

7578
@Override
7679
public ObjectWriter getItemWriter(JSONWriter jsonWriter, Type itemType) {
80+
if (contentAs != null) {
81+
ObjectWriter itemObjectWriter = this.itemObjectWriter;
82+
if (itemObjectWriter != null) {
83+
return itemObjectWriter;
84+
}
85+
return this.itemObjectWriter = jsonWriter.getObjectWriter(this.contentAs, contentAs);
86+
}
7787
if (itemType == null || itemType == this.itemType) {
7888
if (itemObjectWriter != null) {
7989
return itemObjectWriter;

0 commit comments

Comments
 (0)