Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
126 additions
and
49 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
39 changes: 39 additions & 0 deletions
39
value-fixture/src/org/immutables/fixture/jackson/PolymorphicMappings.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,39 @@ | ||
package org.immutables.fixture.jackson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
|
||
public interface PolymorphicMappings { | ||
@JsonSubTypes({ | ||
@Type(DatasetIdLocator.class), | ||
@Type(DatasetPathLocator.class), | ||
@Type(ImmutableDatasetIdLocator.class), | ||
@Type(ImmutableDatasetPathLocator.class) | ||
}) | ||
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "@class", visible = false) | ||
public interface DatasetLocator {} | ||
|
||
@Value.Immutable | ||
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE) | ||
@JsonSerialize(as = ImmutableDatasetIdLocator.class) | ||
@JsonDeserialize(as = ImmutableDatasetIdLocator.class) | ||
public interface DatasetIdLocator extends DatasetLocator { | ||
String getDatasetId(); | ||
class Builder extends ImmutableDatasetIdLocator.Builder {} | ||
} | ||
|
||
@Value.Immutable | ||
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE) | ||
@JsonSerialize(as = ImmutableDatasetIdLocator.class) | ||
@JsonDeserialize(as = ImmutableDatasetIdLocator.class) | ||
public interface DatasetPathLocator extends DatasetLocator { | ||
String getDatasetPath(); | ||
class Builder extends ImmutableDatasetPathLocator.Builder {} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
value-fixture/test/org/immutables/fixture/jackson/PolymorphicTest.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,20 @@ | ||
package org.immutables.fixture.jackson; | ||
|
||
import static org.immutables.check.Checkers.*; | ||
import org.immutables.fixture.jackson.PolymorphicMappings.DatasetLocator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import org.immutables.fixture.jackson.PolymorphicMappings.DatasetIdLocator; | ||
import org.junit.Test; | ||
|
||
public class PolymorphicTest { | ||
ObjectMapper om = new ObjectMapper(); | ||
|
||
@Test | ||
public void polymorphic() throws IOException { | ||
DatasetIdLocator locator = new DatasetIdLocator.Builder().datasetId("id").build(); | ||
DatasetLocator value = om.readValue(om.writeValueAsBytes(locator), DatasetLocator.class); | ||
check(value).isA(DatasetIdLocator.class); | ||
check(((DatasetIdLocator) value).getDatasetId()).is(locator.getDatasetId()); | ||
} | ||
} |
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