-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialize & deserialize org.joda.time.DateTime with jsonb
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
core/src/test/java/com/alibaba/fastjson2/issues_2500/Issue2563.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,40 @@ | ||
package com.alibaba.fastjson2.issues_2500; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONB; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.Data; | ||
import org.joda.time.DateTime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2563 { | ||
DateTime nowD = new DateTime(2018, 7, 14, 12, 13, 14, 0); | ||
|
||
@Test | ||
public void mutatedTest0() { | ||
Bean0 entity = new Bean0(); | ||
entity.setNow(nowD); | ||
|
||
String json = JSON.toJSONString(entity); | ||
Bean0 bean0 = JSON.parseObject(json, Bean0.class); | ||
assertEquals(entity.now, bean0.now); | ||
} | ||
|
||
@Test | ||
public void mutatedTest1() { | ||
Bean0 entity = new Bean0(); | ||
entity.setNow(nowD); | ||
|
||
byte[] jsonbBytes = JSONB.toBytes(entity); | ||
Bean0 bean0 = JSONB.parseObject(jsonbBytes, Bean0.class); | ||
assertEquals(entity.now, bean0.now); | ||
} | ||
|
||
@Data | ||
public static class Bean0 { | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
private DateTime now; | ||
} | ||
} |