Skip to content

Commit

Permalink
Add failing test for #2461
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 17, 2019
1 parent f8738e8 commit a8be137
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.*;

public class UnwrappedCaching2461Test extends BaseMapTest
{
// [databind#2461]
static class Base {
public String id;

Base(String id) {
this.id = id;
}
}

static class BaseContainer {
@JsonUnwrapped(prefix = "base.")
public Base base;

BaseContainer(Base base) {
this.base = base;
}
}

static class BaseContainerContainer {
@JsonUnwrapped(prefix = "container.")
public BaseContainer container;

BaseContainerContainer(BaseContainer container) {
this.container = container;
}
}

// [databind#2461]
public void testUnwrappedCaching() throws Exception {
final BaseContainer inner = new BaseContainer(new Base("12345"));
final BaseContainerContainer outer = new BaseContainerContainer(inner);

final ObjectMapper mapperOrder1 = newJsonMapper();
assertEquals("{\"container.base.id\":\"12345\"}", mapperOrder1.writeValueAsString(outer));
assertEquals("{\"base.id\":\"12345\"}", mapperOrder1.writeValueAsString(inner));
assertEquals("{\"container.base.id\":\"12345\"}", mapperOrder1.writeValueAsString(outer));

final ObjectMapper mapperOrder2 = newJsonMapper();
assertEquals("{\"base.id\":\"12345\"}", mapperOrder2.writeValueAsString(inner));
// Will fail here
assertEquals("{\"container.base.id\":\"12345\"}", mapperOrder2.writeValueAsString(outer));
}
}

0 comments on commit a8be137

Please sign in to comment.