Skip to content

Commit

Permalink
Add unit tests for #88
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 11, 2014
1 parent 0f7358f commit 8221fe1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

import static org.junit.Assert.*;


import com.fasterxml.jackson.databind.*;

/**
* Unit tests to verify that Java/JSON scalar values (non-structured values)
* are handled properly with respect to additional type information.
*
* @since 1.5
* @author tatu
*/
public class TestDefaultForScalars
extends BaseMapTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.failing;

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

public class TestNodeTypingIssue88 extends BaseMapTest
{
public static class Foo {
public String bar;

public Foo() { }
public Foo(String b) { bar = b; }
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

public void testValueAsStringWithDefaultTyping() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);

Foo foo = new Foo("baz");
String json = mapper.writeValueAsString(foo);

JsonNode jsonNode = mapper.readTree(json);
assertEquals(jsonNode.get("bar").textValue(), foo.bar);
}

public void testValueToTreeWithDefaultTyping() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);

Foo foo = new Foo("baz");
JsonNode jsonNode = mapper.valueToTree(foo);
assertEquals(jsonNode.get("bar").textValue(), foo.bar);
}
}

0 comments on commit 8221fe1

Please sign in to comment.