Skip to content

Commit

Permalink
Merge pull request #121 from alibaba/graal
Browse files Browse the repository at this point in the history
bug fix for graal support
  • Loading branch information
wenshao authored May 1, 2022
2 parents 387c124 + 2c3d794 commit 833b8dc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
18 changes: 5 additions & 13 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderStr.java
Original file line number Diff line number Diff line change
Expand Up @@ -3146,6 +3146,8 @@ protected ZonedDateTime readZonedDateTimeX(int len) {

char first = str.charAt(this.offset + zoneIdBegin);

LocalDateTime ldt = getLocalDateTime(y0, y1, y2, y3, m0, m1, d0, d1, h0, h1, i0, i1, s0, s1, S0, S1, S2, S3, S4, S5, S6, S7, S8);

ZoneId zoneId;
if (isTimeZone) {
String tzStr = this.str.substring(this.offset + zoneIdBegin, this.offset + len);
Expand All @@ -3162,29 +3164,19 @@ protected ZonedDateTime readZonedDateTimeX(int len) {
;
// zoneIdStr = new String(chars, this.offset + zoneIdBegin, len - zoneIdBegin);
} else if (first == ' ') {
zoneIdStr = this.str.substring(this.offset + zoneIdBegin + 1, this.offset + len - 1);
zoneIdStr = this.str.substring(this.offset + zoneIdBegin + 1, this.offset + len);
} else { // '[
if (zoneIdBegin < len) {
zoneIdStr = this.str.substring(this.offset + zoneIdBegin + 1, this.offset + len - 1);
} else {
zoneIdStr = null;
}
}
if (zoneIdStr != null) {
if (zoneIdStr.equals("000")) {
zoneId = UTC;
} else if (zoneIdStr.equals("+08:00[Asia/Shanghai]") || zoneIdStr.equals("Asia/Shanghai")) {
zoneId = SHANGHAI;
} else {
zoneId = ZoneId.of(zoneIdStr);
}
} else {
zoneId = context.getZoneId();
}
zoneId = getZoneId(ldt, zoneIdStr);
}
}

ZonedDateTime zdt = getZonedDateTime(y0, y1, y2, y3, m0, m1, d0, d1, h0, h1, i0, i1, s0, s1, S0, S1, S2, S3, S4, S5, S6, S7, S8, zoneId);
ZonedDateTime zdt = ldt.atZone(zoneId);
if (zdt == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void readFieldValue(JSONReader jsonReader, T object) {
JSONReader.Context ctx = context;
ObjectReader itemObjectReader = getItemObjectReader(ctx);

List list = createList();
Collection list = (Collection) this.fieldObjectReader.createInstance(jsonReader.getContext().getFeatures() | features);
jsonReader.next();
for (; ; ) {
if (jsonReader.nextIfMatch(']')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ public T readObject(JSONReader jsonReader, long features) {
}

long nameHashCodeLCase = jsonReader.getNameHashCodeLCase();
if (nameHashCodeLCase == hashCode0) {
if (nameHashCodeLCase == hashCode0LCase) {
fieldReader0.readFieldValue(jsonReader, object);
} else if (nameHashCodeLCase == hashCode1) {
} else if (nameHashCodeLCase == hashCode1LCase) {
fieldReader1.readFieldValue(jsonReader, object);
} else if (nameHashCodeLCase == hashCode2) {
} else if (nameHashCodeLCase == hashCode2LCase) {
fieldReader2.readFieldValue(jsonReader, object);
} else {
jsonReader.skipValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public void getFieldInfo(FieldInfo fieldInfo, Class objectType, Field field) {
jsonFieldFormat = jsonFieldFormat.replaceAll("T", "'T'");
}

fieldInfo.format = jsonFieldFormat;
if (!jsonFieldFormat.isEmpty()) {
fieldInfo.format = jsonFieldFormat;
}
}

if (!fieldInfo.ignore) {
Expand Down Expand Up @@ -272,7 +274,9 @@ private void processJSONField1x(FieldInfo fieldInfo, Annotation annotation) {
format = format.replaceAll("T", "'T'");
}

fieldInfo.format = format;
if (!format.isEmpty()) {
fieldInfo.format = format;
}
}
break;
}
Expand Down Expand Up @@ -414,7 +418,9 @@ public void getFieldInfo(FieldInfo fieldInfo, Class objectClass, Method method)
jsonFieldFormat = jsonFieldFormat.replaceAll("T", "'T'");
}

fieldInfo.format = jsonFieldFormat;
if (!jsonFieldFormat.isEmpty()) {
fieldInfo.format = jsonFieldFormat;
}
}

if (!fieldInfo.ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public void test_codec_asm() {
V0 v = new V0();
v.setValue(new Date());

SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(true);

String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
String text = JSON.toJSONString(v, SerializerFeature.WriteMapNullValue);
Assert.assertEquals("{\"value\":" + v.getValue().getTime() + "}", text);
}

Expand Down

0 comments on commit 833b8dc

Please sign in to comment.