-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/miho/VMF/issues/64
- Loading branch information
Showing
12 changed files
with
484 additions
and
45 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
7 changes: 7 additions & 0 deletions
7
jackson/src/test/java/eu/mihosoft/vmf/jackson/test/external_types01/ExternalEnum.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,7 @@ | ||
package eu.mihosoft.vmf.jackson.test.external_types01; | ||
|
||
public enum ExternalEnum { | ||
FIRST, | ||
SECOND, | ||
THIRD | ||
} |
45 changes: 45 additions & 0 deletions
45
.../src/test/java/eu/mihosoft/vmf/jackson/test/external_types01/ExternalTypeModel01Test.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,45 @@ | ||
package eu.mihosoft.vmf.jackson.test.external_types01; | ||
|
||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import eu.mihosoft.vmf.jackson.VMFJacksonModule; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ExternalTypeModel01Test { | ||
|
||
@org.junit.jupiter.api.Test | ||
void testModel() throws JsonProcessingException { | ||
|
||
ExternalTypeModel01 model = ExternalTypeModel01.newBuilder() | ||
.withName("Model 01") | ||
.withEnumValue(ExternalEnum.SECOND) | ||
.withTags(new String[]{"tag1", "tag2", "tag3"}) | ||
.withValues(new Integer[]{1, 2, 3}) | ||
.build(); | ||
|
||
var mapper = new ObjectMapper(); | ||
|
||
mapper.registerModule(VMFJacksonModule.newInstance(VMFJacksonModule.RUNTIME_TYPE.EXPERIMENTAL) | ||
.withTypeAlias("external-type-model-01", ExternalTypeModel01.class.getName()) | ||
.withTypeAlias("external-enum", ExternalEnum.class.getName()) | ||
); | ||
|
||
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model); | ||
System.out.println(json); | ||
|
||
// deserialize | ||
ExternalTypeModel01 model2 = mapper.readValue(json, ExternalTypeModel01.class); | ||
|
||
// serialize again | ||
String json2 = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model2); | ||
System.out.println(json2); | ||
|
||
// check if deserialization worked | ||
assertTrue(model.vmf().content().equals(model2)); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.