-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
9561cfb
commit 02c7345
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/test/java/com/fasterxml/jackson/failing/JsonIdentityInfo2759Test.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,72 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIdentityInfo; | ||
import com.fasterxml.jackson.annotation.ObjectIdGenerators; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class JsonIdentityInfo2759Test extends BaseMapTest | ||
{ | ||
static class Bee { | ||
public Long id; | ||
|
||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") | ||
/// @JsonIdentityReference(alwaysAsId = true) | ||
// @JsonProperty("hiveId") | ||
Hive hive; | ||
|
||
public Bee() { } | ||
|
||
public Bee(Long id, Hive hive) { | ||
this.id = id; | ||
this.hive = hive; | ||
} | ||
|
||
public Hive getHive() { | ||
return hive; | ||
} | ||
|
||
public void setHive(Hive hive) { | ||
this.hive = hive; | ||
} | ||
} | ||
|
||
static class Hive { | ||
public String name; | ||
public List<Bee> bees = new ArrayList<>(); | ||
|
||
public Long id; | ||
|
||
Hive() { } | ||
|
||
public Hive(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public void addBee(Bee bee) { | ||
bees.add(bee); | ||
} | ||
} | ||
|
||
public void testObjectId2759() throws Exception | ||
{ | ||
Hive hive = new Hive(100500L, "main hive"); | ||
hive.addBee(new Bee(1L, hive)); | ||
|
||
ObjectMapper mapper = newJsonMapper(); | ||
final String json = mapper.writerWithDefaultPrettyPrinter() | ||
.writeValueAsString(hive); | ||
|
||
try { | ||
mapper.readerFor(JsonNode.class) | ||
.with(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY) | ||
.readValue(json); | ||
} catch (JsonMappingException e) { | ||
fail("Should not have duplicates, but JSON content has: "+json); | ||
} | ||
} | ||
} |