11package org .folio .edge .api .utils ;
22
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .is ;
35import static org .junit .Assert .assertEquals ;
46
5- import com .fasterxml .jackson .databind .ObjectMapper ;
6- import com .fasterxml .jackson .databind .node .ObjectNode ;
7- import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
8- import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlRootElement ;
7+ import com .fasterxml .jackson .annotation .JsonProperty ;
8+ import com .fasterxml .jackson .annotation .JsonRootName ;
9+ import java .time .OffsetDateTime ;
910import java .util .HashMap ;
1011import java .util .Map ;
1112import org .junit .Test ;
13+ import tools .jackson .databind .json .JsonMapper ;
1214
1315public class MappersTest {
1416
@@ -17,8 +19,8 @@ public void testJsonMapper() throws Exception {
1719 String key = "foo" ;
1820 String value = "bar" ;
1921
20- ObjectMapper mapper = new ObjectMapper ();
21- ObjectNode node = mapper .createObjectNode ();
22+ var mapper = JsonMapper . shared ();
23+ var node = mapper .createObjectNode ();
2224 node .put (key , value );
2325
2426 String json = node .toPrettyString ();
@@ -54,15 +56,24 @@ public void testXmlMapper() throws Exception {
5456 assertEquals (obj .b , asObj .b );
5557 }
5658
57- @ JacksonXmlRootElement (localName = "test" )
59+ @ Test
60+ public void testJsonDate () {
61+ var datestring1 = "\" 1999-12-31T23:59:58.765Z\" " ;
62+ var date = Mappers .jsonMapper .readValue (datestring1 , OffsetDateTime .class );
63+ assertThat (date .toString (), is ("1999-12-31T23:59:58.765Z" ));
64+ var datestring2 = Mappers .jsonMapper .writeValueAsString (date );
65+ assertThat (datestring2 , is (datestring1 ));
66+ }
67+
68+ @ JsonRootName (value = "test" )
5869 public static class TestObject {
5970
60- @ JacksonXmlProperty ( localName = "a" )
71+ @ JsonProperty ( value = "a" )
6172 private String a ;
62- @ JacksonXmlProperty ( localName = "b" )
73+ @ JsonProperty ( value = "b" )
6374 private String b ;
6475
65- public TestObject (@ JacksonXmlProperty ( localName = "a" ) String a , @ JacksonXmlProperty ( localName = "b" ) String b ) {
76+ public TestObject (@ JsonProperty ( value = "a" ) String a , @ JsonProperty ( value = "b" ) String b ) {
6677 this .a = a ;
6778 this .b = b ;
6879 }
0 commit comments