-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
416e938
commit 4248b13
Showing
7 changed files
with
181 additions
and
83 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/de/hamburgchimps/jackson/NoAnnotationExamplePojo.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,29 @@ | ||
package de.hamburgchimps.jackson; | ||
|
||
public class NoAnnotationExamplePojo { | ||
private String example; | ||
private String demo; | ||
|
||
public NoAnnotationExamplePojo() {} | ||
|
||
public NoAnnotationExamplePojo(String example, String demo) { | ||
this.example = example; | ||
this.demo = demo; | ||
} | ||
|
||
public String getExample() { | ||
return example; | ||
} | ||
|
||
public void setExample(String example) { | ||
this.example = example; | ||
} | ||
|
||
public String getDemo() { | ||
return demo; | ||
} | ||
|
||
public void setDemo(String demo) { | ||
this.demo = demo; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/de/hamburgchimps/jackson/NoAnnotationExampleRecord.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,3 @@ | ||
package de.hamburgchimps.jackson; | ||
|
||
public record NoAnnotationExampleRecord(String example, String demo) {} |
52 changes: 52 additions & 0 deletions
52
src/test/java/de/hamburgchimps/jackson/TestPojoDeserialization.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,52 @@ | ||
package de.hamburgchimps.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestPojoDeserialization { | ||
private static final XmlMapper xmlMapper = new XmlMapper(); | ||
|
||
private static final String NO_ANNOTATION_EXAMPLE_POJO_XML; | ||
private static final String JSON_PROPERTY_NO_ARGS_EXAMPLE_POJO_XML; | ||
private static final String XML_ANNOTATION_NO_ARGS_EXAMPLE_POJO_XML; | ||
private static final String JSON_PROPERTY_WITH_ARG_EXAMPLE_POJO_XML; | ||
private static final String XML_ANNOTATION_WITH_ARG_EXAMPLE_POJO_XML; | ||
|
||
static { | ||
try { | ||
NO_ANNOTATION_EXAMPLE_POJO_XML = xmlMapper.writeValueAsString(new NoAnnotationExamplePojo("hooray", "oh no")); | ||
JSON_PROPERTY_NO_ARGS_EXAMPLE_POJO_XML = xmlMapper.writeValueAsString(new JsonPropertyNoArgsExamplePojo("hooray", "oh no")); | ||
XML_ANNOTATION_NO_ARGS_EXAMPLE_POJO_XML = xmlMapper.writeValueAsString(new XmlAnnotationNoArgsExamplePojo("hooray", "oh no")); | ||
JSON_PROPERTY_WITH_ARG_EXAMPLE_POJO_XML = xmlMapper.writeValueAsString(new JsonPropertyWithArgExamplePojo("hooray", "oh no")); | ||
XML_ANNOTATION_WITH_ARG_EXAMPLE_POJO_XML = xmlMapper.writeValueAsString(new XmlAnnotationWithArgExamplePojo("hooray", "oh no")); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
void NoAnnotation_pojo() throws JsonProcessingException { | ||
xmlMapper.readValue(NO_ANNOTATION_EXAMPLE_POJO_XML, NoAnnotationExamplePojo.class); | ||
} | ||
|
||
@Test | ||
void JsonProperty_pojo_no_args() throws JsonProcessingException { | ||
xmlMapper.readValue(JSON_PROPERTY_NO_ARGS_EXAMPLE_POJO_XML, JsonPropertyNoArgsExamplePojo.class); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_pojo_no_args() throws JsonProcessingException { | ||
xmlMapper.readValue(XML_ANNOTATION_NO_ARGS_EXAMPLE_POJO_XML, XmlAnnotationNoArgsExamplePojo.class); | ||
} | ||
|
||
@Test | ||
void JsonProperty_pojo_with_arg() throws JsonProcessingException { | ||
xmlMapper.readValue(JSON_PROPERTY_WITH_ARG_EXAMPLE_POJO_XML, JsonPropertyWithArgExamplePojo.class); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_pojo_with_arg() throws JsonProcessingException { | ||
xmlMapper.readValue(XML_ANNOTATION_WITH_ARG_EXAMPLE_POJO_XML, XmlAnnotationWithArgExamplePojo.class); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/de/hamburgchimps/jackson/TestPojoSerialization.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,46 @@ | ||
package de.hamburgchimps.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestPojoSerialization { | ||
static final XmlMapper xmlMapper = new XmlMapper(); | ||
|
||
@BeforeAll | ||
static void setUpMapper() { | ||
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
} | ||
|
||
@Test | ||
void NoAnnotation_pojo() throws JsonProcessingException { | ||
var exampleFromNoAnnotationPojo = new NoAnnotationExamplePojo("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromNoAnnotationPojo)); | ||
} | ||
|
||
@Test | ||
void JsonProperty_pojo_no_args() throws JsonProcessingException { | ||
var exampleFromJsonPropertyNoArgsPojo = new JsonPropertyNoArgsExamplePojo("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromJsonPropertyNoArgsPojo)); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_pojo_no_args() throws JsonProcessingException { | ||
var exampleFromXmlAnnotationNoArgsExamplePojo = new XmlAnnotationNoArgsExamplePojo("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromXmlAnnotationNoArgsExamplePojo)); | ||
} | ||
|
||
@Test | ||
void JsonProperty_pojo_with_arg() throws JsonProcessingException { | ||
var exampleFromJsonPropertyWithArgPojo = new JsonPropertyWithArgExamplePojo("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromJsonPropertyWithArgPojo)); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_pojo_with_arg() throws JsonProcessingException { | ||
var exampleFromXmlAnnotationWithArgPojo = new XmlAnnotationWithArgExamplePojo("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromXmlAnnotationWithArgPojo)); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
src/test/java/de/hamburgchimps/jackson/TestRecordSerialization.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,46 @@ | ||
package de.hamburgchimps.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestRecordSerialization { | ||
static final XmlMapper xmlMapper = new XmlMapper(); | ||
|
||
@BeforeAll | ||
static void setUpMapper() { | ||
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
} | ||
|
||
@Test | ||
void NoAnnotation_record() throws JsonProcessingException { | ||
var exampleFromNoAnnotationRecord = new NoAnnotationExampleRecord("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromNoAnnotationRecord)); | ||
} | ||
|
||
@Test | ||
void JsonProperty_record_no_args() throws JsonProcessingException { | ||
var exampleFromJsonPropertyNoArgsRecord = new JsonPropertyNoArgsExampleRecord("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromJsonPropertyNoArgsRecord)); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_record_no_args() throws JsonProcessingException { | ||
var exampleFromXmlAnnotationNoArgsExampleRecord = new XmlAnnotationNoArgsExampleRecord("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromXmlAnnotationNoArgsExampleRecord)); | ||
} | ||
|
||
@Test | ||
void JsonProperty_record_with_arg() throws JsonProcessingException { | ||
var exampleFromJsonPropertyWithArgRecord = new JsonPropertyWithArgExampleRecord("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromJsonPropertyWithArgRecord)); | ||
} | ||
|
||
@Test | ||
void JacksonXmlProperty_record_with_arg() throws JsonProcessingException { | ||
var exampleFromXmlAnnotationWithArgRecord = new XmlAnnotationWithArgExampleRecord("hooray", "oh no"); | ||
System.out.println(xmlMapper.writeValueAsString(exampleFromXmlAnnotationWithArgRecord)); | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
src/test/java/de/hamburgchimps/jackson/TestSerialization.java
This file was deleted.
Oops, something went wrong.