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.
- Loading branch information
Showing
9 changed files
with
455 additions
and
35 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
356 changes: 331 additions & 25 deletions
356
generated/main/java/org/inferred/freebuilder/processor/property/Property_Builder.java
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/it/vanilla/src/main/java/org/inferred/freebuilder/JacksonAnyGetterType.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,19 @@ | ||
package org.inferred.freebuilder; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import java.util.Map; | ||
|
||
@FreeBuilder | ||
@JsonDeserialize(builder = JacksonAnyGetterType.Builder.class) | ||
public interface JacksonAnyGetterType { | ||
@JsonProperty("simple_property") | ||
String getSimpleProperty(); | ||
@JsonAnyGetter | ||
Map<String, JsonNode> getUnknownProperties(); | ||
|
||
class Builder extends JacksonAnyGetterType_Builder {} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/it/vanilla/src/test/java/org/inferred/freebuilder/JacksonAnyGetterTypeTest.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 org.inferred.freebuilder; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.IntNode; | ||
import com.fasterxml.jackson.databind.node.TextNode; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class JacksonAnyGetterTypeTest { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void testDeserializeJsonWithAnyGetter() throws IOException { | ||
JacksonAnyGetterType parsed = objectMapper.readValue( | ||
"{\"simple_property\": \"simpleValue\", \"other_property\": 3}", | ||
JacksonAnyGetterType.class); | ||
|
||
assertEquals("simpleValue", parsed.getSimpleProperty()); | ||
assertNotNull(parsed.getUnknownProperties()); | ||
assertEquals(1, parsed.getUnknownProperties().size()); | ||
assertEquals(new IntNode(3), parsed.getUnknownProperties().get("other_property")); | ||
} | ||
|
||
@Test | ||
public void testSerializeJsonWithAnyGetter() throws JsonProcessingException { | ||
JacksonAnyGetterType getterType = new JacksonAnyGetterType.Builder() | ||
.setSimpleProperty("checkValue") | ||
.putUnknownProperties("propertyOne", new TextNode("abc")) | ||
.putUnknownProperties("propertyTwo", new IntNode(2)).build(); | ||
|
||
String json = objectMapper.writeValueAsString(getterType); | ||
assertTrue("should contain simple_property", | ||
json.contains("\"simple_property\":\"checkValue\"")); | ||
assertTrue("should contain propertyOne", json.contains("\"propertyOne\":\"abc\"")); | ||
assertTrue("should contain propertyTwo", json.contains("\"propertyTwo\":2")); | ||
} | ||
|
||
} |
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
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