This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JsonAlias annotation (#462)
Copy JsonAlias annotations to the generated getter/setter methods.
- Loading branch information
Showing
4 changed files
with
87 additions
and
12 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
54 changes: 54 additions & 0 deletions
54
src/test/java/org/inferred/freebuilder/processor/JacksonIntegrationTest.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,54 @@ | ||
package org.inferred.freebuilder.processor; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import org.inferred.freebuilder.FreeBuilder; | ||
import org.inferred.freebuilder.processor.source.SourceBuilder; | ||
import org.inferred.freebuilder.processor.source.feature.FeatureSet; | ||
import org.inferred.freebuilder.processor.source.feature.StaticFeatureSet; | ||
import org.inferred.freebuilder.processor.source.testing.BehaviorTester; | ||
import org.inferred.freebuilder.processor.source.testing.ParameterizedBehaviorTestFactory.Shared; | ||
import org.inferred.freebuilder.processor.source.testing.TestBuilder; | ||
import org.junit.Test; | ||
|
||
public class JacksonIntegrationTest { | ||
|
||
@Shared public BehaviorTester behaviorTester; | ||
|
||
@Test | ||
public void testJsonAliasSupport() { | ||
FeatureSet featureSet = new StaticFeatureSet(); | ||
BehaviorTester.create(featureSet) | ||
.with(new Processor(featureSet)) | ||
.with(SourceBuilder.forTesting() | ||
.addLine("package com.example;") | ||
.addLine("@%s", FreeBuilder.class) | ||
.addLine("@%s(builder = DataType.Builder.class)", JsonDeserialize.class) | ||
.addLine("public abstract class DataType {") | ||
.addLine(" @%s({\"a\", \"theagame\"})", JsonAlias.class) | ||
.addLine(" public abstract int propertyA();") | ||
.addLine("") | ||
.addLine(" public static class Builder extends DataType_Builder {}") | ||
.addLine("}")) | ||
.with(testBuilder() | ||
.addLine("DataType expected = new DataType.Builder().propertyA(13).build();") | ||
.addLine("%1$s mapper = new %1$s();", ObjectMapper.class) | ||
.addLine("String canonicalJson = \"{ \\\"propertyA\\\": 13 }\";") | ||
.addLine("DataType canonical = mapper.readValue(canonicalJson, DataType.class);") | ||
.addLine("assertEquals(expected, canonical);") | ||
.addLine("String alternative1Json = \"{ \\\"a\\\": 13 }\";") | ||
.addLine("DataType alternative1 = mapper.readValue(canonicalJson, DataType.class);") | ||
.addLine("assertEquals(expected, alternative1);") | ||
.addLine("String alternative2Json = \"{ \\\"theagame\\\": 13 }\";") | ||
.addLine("DataType alternative2 = mapper.readValue(canonicalJson, DataType.class);") | ||
.addLine("assertEquals(expected, alternative2);") | ||
.build()) | ||
.runTest(); | ||
} | ||
|
||
private static TestBuilder testBuilder() { | ||
return new TestBuilder().addImport("com.example.DataType"); | ||
} | ||
} |
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