Skip to content

Commit 0bbd0d1

Browse files
committed
improved android support
1 parent add5b5e commit 0bbd0d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+875
-560
lines changed

benchmark/src/test/java/com/alibaba/fastjson2/benchmark/jjb/ClientsParseUTF8BytesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static void fastjson2() {
1616
// zulu17.40.19 : 2850 2815 2777 2770 2730 2704 2717 2661 2638 2603 2587 2662
1717
// oracle-jdk-17.0.6 :
1818
// oracle-jdk-17.0.6_vec :
19+
// oracle-jdk-17.0.6_reflect : 3566 3513 3476
1920
}
2021
}
2122

benchmark/src/test/java/com/alibaba/fastjson2/benchmark/jjb/ClientsWriteUTF8BytesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static void fastjson2() {
1616
// zulu8.70.0.23 : 1533 1493
1717
// zulu17.40.19 : 1419 1361 1356
1818
// zulu17.40.19_vec : 1116
19+
// zulu17.40.19_reflect : 1427
1920
}
2021
}
2122

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,6 @@ public final void writeName(long name) {
827827
}
828828

829829
writeInt64(name);
830-
831-
if (name >= Integer.MIN_VALUE && name <= Integer.MAX_VALUE && (context.features & Feature.WriteClassName.mask) != 0) {
832-
writeRaw('L');
833-
}
834830
}
835831

836832
public final void writeName(int name) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,10 @@ public final void writeInt64(long i) {
17111711
off = IOUtils.writeInt64(chars, off, i);
17121712
if (writeAsString) {
17131713
chars[off++] = quote;
1714+
} else if ((context.features & WriteClassName.mask) != 0
1715+
&& i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE
1716+
) {
1717+
chars[off++] = 'L';
17141718
}
17151719
this.off = off;
17161720
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,10 @@ public final void writeInt64(long i) {
17531753
off = IOUtils.writeInt64(bytes, off, i);
17541754
if (writeAsString) {
17551755
bytes[off++] = (byte) quote;
1756+
} else if ((context.features & WriteClassName.mask) != 0
1757+
&& i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE
1758+
) {
1759+
bytes[off++] = 'L';
17561760
}
17571761
this.off = off;
17581762
}

core/src/main/java/com/alibaba/fastjson2/reader/FieldReader.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,7 @@ static ObjectReader createFormattedObjectReader(Type fieldType, Class fieldClass
433433
}
434434

435435
if (fieldClass == LocalDate.class) {
436-
if (format == null) {
437-
return ObjectReaderImplLocalDate.INSTANCE;
438-
}
439-
440-
return new ObjectReaderImplLocalDate(format, locale);
436+
return ObjectReaderImplLocalDate.of(format, locale);
441437
}
442438

443439
if (fieldClass == LocalTime.class) {

core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderDate.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Locale;
1818
import java.util.function.BiConsumer;
1919

20-
class FieldReaderDate<T>
20+
final class FieldReaderDate<T>
2121
extends FieldReaderDateTimeCodec<T> {
2222
final BiConsumer<T, Date> function;
2323

@@ -35,7 +35,19 @@ public FieldReaderDate(
3535
Method method,
3636
BiConsumer<T, Date> function
3737
) {
38-
super(fieldName, fieldType, fieldClass, ordinal, features, format, locale, defaultValue, schema, method, field);
38+
super(
39+
fieldName,
40+
fieldType,
41+
fieldClass,
42+
ordinal,
43+
features,
44+
format,
45+
locale,
46+
defaultValue,
47+
schema, method,
48+
field,
49+
ObjectReaderImplDate.of(format, locale)
50+
);
3951
this.function = function;
4052
}
4153

@@ -44,6 +56,12 @@ protected void acceptNull(T object) {
4456
accept(object, (Date) null);
4557
}
4658

59+
@Override
60+
public void readFieldValue(JSONReader jsonReader, T object) {
61+
Date date = (Date) dateReader.readObject(jsonReader, fieldType, fieldName, features);
62+
accept(object, date);
63+
}
64+
4765
@Override
4866
protected void accept(T object, Date value) {
4967
if (function != null) {
@@ -129,23 +147,4 @@ protected Object apply(ZonedDateTime zdt) {
129147
protected Object apply(long millis) {
130148
return new Date(millis);
131149
}
132-
133-
@Override
134-
public ObjectReader getObjectReader(JSONReader jsonReader) {
135-
if (dateReader == null) {
136-
dateReader = format == null
137-
? ObjectReaderImplDate.INSTANCE
138-
: new ObjectReaderImplDate(format, locale);
139-
}
140-
return dateReader;
141-
}
142-
143-
public ObjectReader getObjectReader(JSONReader.Context context) {
144-
if (dateReader == null) {
145-
dateReader = format == null
146-
? ObjectReaderImplDate.INSTANCE
147-
: new ObjectReaderImplDate(format, locale);
148-
}
149-
return dateReader;
150-
}
151150
}

0 commit comments

Comments
 (0)