Skip to content

Commit

Permalink
Add failing test for #2759
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 16, 2020
1 parent 9561cfb commit 02c7345
Showing 1 changed file with 72 additions and 0 deletions.
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);
}
}
}

0 comments on commit 02c7345

Please sign in to comment.