Skip to content

Commit

Permalink
improved android support
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 27, 2023
1 parent add5b5e commit 0bbd0d1
Show file tree
Hide file tree
Showing 45 changed files with 875 additions and 560 deletions.
Expand Up @@ -16,6 +16,7 @@ public static void fastjson2() {
// zulu17.40.19 : 2850 2815 2777 2770 2730 2704 2717 2661 2638 2603 2587 2662
// oracle-jdk-17.0.6 :
// oracle-jdk-17.0.6_vec :
// oracle-jdk-17.0.6_reflect : 3566 3513 3476
}
}

Expand Down
Expand Up @@ -16,6 +16,7 @@ public static void fastjson2() {
// zulu8.70.0.23 : 1533 1493
// zulu17.40.19 : 1419 1361 1356
// zulu17.40.19_vec : 1116
// zulu17.40.19_reflect : 1427
}
}

Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriter.java
Expand Up @@ -827,10 +827,6 @@ public final void writeName(long name) {
}

writeInt64(name);

if (name >= Integer.MIN_VALUE && name <= Integer.MAX_VALUE && (context.features & Feature.WriteClassName.mask) != 0) {
writeRaw('L');
}
}

public final void writeName(int name) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF16.java
Expand Up @@ -1711,6 +1711,10 @@ public final void writeInt64(long i) {
off = IOUtils.writeInt64(chars, off, i);
if (writeAsString) {
chars[off++] = quote;
} else if ((context.features & WriteClassName.mask) != 0
&& i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE
) {
chars[off++] = 'L';
}
this.off = off;
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
Expand Up @@ -1753,6 +1753,10 @@ public final void writeInt64(long i) {
off = IOUtils.writeInt64(bytes, off, i);
if (writeAsString) {
bytes[off++] = (byte) quote;
} else if ((context.features & WriteClassName.mask) != 0
&& i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE
) {
bytes[off++] = 'L';
}
this.off = off;
}
Expand Down
Expand Up @@ -433,11 +433,7 @@ static ObjectReader createFormattedObjectReader(Type fieldType, Class fieldClass
}

if (fieldClass == LocalDate.class) {
if (format == null) {
return ObjectReaderImplLocalDate.INSTANCE;
}

return new ObjectReaderImplLocalDate(format, locale);
return ObjectReaderImplLocalDate.of(format, locale);
}

if (fieldClass == LocalTime.class) {
Expand Down
Expand Up @@ -17,7 +17,7 @@
import java.util.Locale;
import java.util.function.BiConsumer;

class FieldReaderDate<T>
final class FieldReaderDate<T>
extends FieldReaderDateTimeCodec<T> {
final BiConsumer<T, Date> function;

Expand All @@ -35,7 +35,19 @@ public FieldReaderDate(
Method method,
BiConsumer<T, Date> function
) {
super(fieldName, fieldType, fieldClass, ordinal, features, format, locale, defaultValue, schema, method, field);
super(
fieldName,
fieldType,
fieldClass,
ordinal,
features,
format,
locale,
defaultValue,
schema, method,
field,
ObjectReaderImplDate.of(format, locale)
);
this.function = function;
}

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

@Override
public void readFieldValue(JSONReader jsonReader, T object) {
Date date = (Date) dateReader.readObject(jsonReader, fieldType, fieldName, features);
accept(object, date);
}

@Override
protected void accept(T object, Date value) {
if (function != null) {
Expand Down Expand Up @@ -129,23 +147,4 @@ protected Object apply(ZonedDateTime zdt) {
protected Object apply(long millis) {
return new Date(millis);
}

@Override
public ObjectReader getObjectReader(JSONReader jsonReader) {
if (dateReader == null) {
dateReader = format == null
? ObjectReaderImplDate.INSTANCE
: new ObjectReaderImplDate(format, locale);
}
return dateReader;
}

public ObjectReader getObjectReader(JSONReader.Context context) {
if (dateReader == null) {
dateReader = format == null
? ObjectReaderImplDate.INSTANCE
: new ObjectReaderImplDate(format, locale);
}
return dateReader;
}
}

0 comments on commit 0bbd0d1

Please sign in to comment.