-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialize OffsetDateTime, for issue #1621
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
core/src/test/java/com/alibaba/fastjson2/issues_1600/Issue1621.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.alibaba.fastjson2.issues_1600; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Serializable; | ||
import java.time.OffsetDateTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1621 { | ||
@Test | ||
public void test() { | ||
final OffsetDateTime defaultDateTime = OffsetDateTime.MIN; | ||
DemoMetadata demoMetadata = DemoMetadata.builder() | ||
.metadataType("TestType") | ||
.lastMetadataRefreshTime(defaultDateTime) | ||
.build(); | ||
Map<String, DemoMetadata> map = new HashMap<>(); | ||
map.put(demoMetadata.getMetadataType(), demoMetadata); | ||
DemoRoot demoRoot = DemoRoot.builder() | ||
.rootName("Root") | ||
.lastMetadataRefreshTime(defaultDateTime) | ||
.dmoToDaoTypeMapping(map) | ||
.build(); | ||
JSONObject jsonObject = (JSONObject) JSON.toJSON(demoRoot); | ||
DemoRoot updatedRoot = jsonObject.toJavaObject(DemoRoot.class); | ||
assertEquals(defaultDateTime, updatedRoot.getLastMetadataRefreshTime()); | ||
} | ||
|
||
@Data | ||
@SuperBuilder | ||
@EqualsAndHashCode(callSuper = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
public static class DemoRoot | ||
extends DemoAbstract { | ||
private static final long serialVersionUID = 1L; | ||
private String rootName; | ||
private Map<String, DemoMetadata> dmoToDaoTypeMapping; | ||
|
||
@Override | ||
public void someFunction() { | ||
} | ||
} | ||
|
||
@Data | ||
@SuperBuilder | ||
@Generated | ||
@EqualsAndHashCode(callSuper = true) | ||
@NoArgsConstructor | ||
@ToString | ||
public static class DemoMetadata | ||
extends DemoAbstract { | ||
private static final long serialVersionUID = 1L; | ||
private String metadataType; | ||
|
||
@Override | ||
public void someFunction() { | ||
} | ||
} | ||
|
||
@SuperBuilder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
public abstract static class DemoAbstract | ||
implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
@EqualsAndHashCode.Exclude | ||
private OffsetDateTime lastMetadataRefreshTime; | ||
|
||
public abstract void someFunction(); | ||
} | ||
} |