Skip to content

Commit 6456a9a

Browse files
committed
Fix #815, for specific case of ObjectNode deserializer access.
1 parent ea2c9a4 commit 6456a9a

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

src/main/java/com/fasterxml/jackson/databind/node/ObjectNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.jackson.databind.node;
22

3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
35
import com.fasterxml.jackson.core.*;
46
import com.fasterxml.jackson.databind.JsonNode;
57
import com.fasterxml.jackson.databind.SerializerProvider;
@@ -320,6 +322,7 @@ public JsonNode set(String fieldName, JsonNode value)
320322
*
321323
* @since 2.1
322324
*/
325+
@JsonIgnore // work-around for [databind#815]
323326
public JsonNode setAll(Map<String,? extends JsonNode> properties)
324327
{
325328
for (Map.Entry<String,? extends JsonNode> en : properties.entrySet()) {

src/test/java/com/fasterxml/jackson/databind/introspect/TestNamingStrategyStd.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
1212
import com.fasterxml.jackson.databind.annotation.JsonNaming;
1313
import com.fasterxml.jackson.databind.introspect.TestNamingStrategyCustom.PersonBean;
14+
import com.fasterxml.jackson.databind.node.ObjectNode;
1415

1516
/**
1617
* Unit tests to verify functioning of
@@ -23,12 +24,6 @@
2324
*/
2425
public class TestNamingStrategyStd extends BaseMapTest
2526
{
26-
/*
27-
/**********************************************************
28-
/* Helper types
29-
/**********************************************************
30-
*/
31-
3227
@JsonPropertyOrder({"www", "some_url", "some_uris"})
3328
static class Acronyms
3429
{
@@ -95,7 +90,12 @@ static class BoringBean {
9590
public String firstName = "Bob";
9691
public String lastName = "Burger";
9792
}
98-
93+
94+
public static class ClassWithObjectNodeField {
95+
public String id;
96+
public ObjectNode json;
97+
}
98+
9999
/*
100100
/**********************************************************
101101
/* Set up
@@ -154,14 +154,14 @@ static class BoringBean {
154154
{"_Bars", "bars" }
155155
});
156156

157-
private ObjectMapper mapper;
157+
private ObjectMapper _lcWithUndescoreMapper;
158158

159159
@Override
160160
public void setUp() throws Exception
161161
{
162162
super.setUp();
163-
mapper = new ObjectMapper();
164-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
163+
_lcWithUndescoreMapper = new ObjectMapper();
164+
_lcWithUndescoreMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
165165
}
166166

167167
/*
@@ -190,11 +190,11 @@ public void testLowerCaseStrategyStandAlone()
190190
public void testLowerCaseTranslations() throws Exception
191191
{
192192
// First serialize
193-
String json = mapper.writeValueAsString(new PersonBean("Joe", "Sixpack", 42));
193+
String json = _lcWithUndescoreMapper.writeValueAsString(new PersonBean("Joe", "Sixpack", 42));
194194
assertEquals("{\"first_name\":\"Joe\",\"last_name\":\"Sixpack\",\"age\":42}", json);
195195

196196
// then deserialize
197-
PersonBean result = mapper.readValue(json, PersonBean.class);
197+
PersonBean result = _lcWithUndescoreMapper.readValue(json, PersonBean.class);
198198
assertEquals("Joe", result.firstName);
199199
assertEquals("Sixpack", result.lastName);
200200
assertEquals(42, result.age);
@@ -203,11 +203,11 @@ public void testLowerCaseTranslations() throws Exception
203203
public void testLowerCaseAcronymsTranslations() throws Exception
204204
{
205205
// First serialize
206-
String json = mapper.writeValueAsString(new Acronyms("world wide web", "http://jackson.codehaus.org", "/path1/,/path2/"));
206+
String json = _lcWithUndescoreMapper.writeValueAsString(new Acronyms("world wide web", "http://jackson.codehaus.org", "/path1/,/path2/"));
207207
assertEquals("{\"www\":\"world wide web\",\"some_url\":\"http://jackson.codehaus.org\",\"some_uris\":\"/path1/,/path2/\"}", json);
208208

209209
// then deserialize
210-
Acronyms result = mapper.readValue(json, Acronyms.class);
210+
Acronyms result = _lcWithUndescoreMapper.readValue(json, Acronyms.class);
211211
assertEquals("world wide web", result.WWW);
212212
assertEquals("http://jackson.codehaus.org", result.someURL);
213213
assertEquals("/path1/,/path2/", result.someURIs);
@@ -216,11 +216,11 @@ public void testLowerCaseAcronymsTranslations() throws Exception
216216
public void testLowerCaseOtherNonStandardNamesTranslations() throws Exception
217217
{
218218
// First serialize
219-
String json = mapper.writeValueAsString(new OtherNonStandardNames("Results", "_User", "___", "$User"));
219+
String json = _lcWithUndescoreMapper.writeValueAsString(new OtherNonStandardNames("Results", "_User", "___", "$User"));
220220
assertEquals("{\"results\":\"Results\",\"user\":\"_User\",\"__\":\"___\",\"$_user\":\"$User\"}", json);
221221

222222
// then deserialize
223-
OtherNonStandardNames result = mapper.readValue(json, OtherNonStandardNames.class);
223+
OtherNonStandardNames result = _lcWithUndescoreMapper.readValue(json, OtherNonStandardNames.class);
224224
assertEquals("Results", result.Results);
225225
assertEquals("_User", result._User);
226226
assertEquals("___", result.___);
@@ -230,11 +230,11 @@ public void testLowerCaseOtherNonStandardNamesTranslations() throws Exception
230230
public void testLowerCaseUnchangedNames() throws Exception
231231
{
232232
// First serialize
233-
String json = mapper.writeValueAsString(new UnchangedNames("from_user", "_user", "from$user", "from7user", "_x"));
233+
String json = _lcWithUndescoreMapper.writeValueAsString(new UnchangedNames("from_user", "_user", "from$user", "from7user", "_x"));
234234
assertEquals("{\"from_user\":\"from_user\",\"user\":\"_user\",\"from$user\":\"from$user\",\"from7user\":\"from7user\",\"x\":\"_x\"}", json);
235235

236236
// then deserialize
237-
UnchangedNames result = mapper.readValue(json, UnchangedNames.class);
237+
UnchangedNames result = _lcWithUndescoreMapper.readValue(json, UnchangedNames.class);
238238
assertEquals("from_user", result.from_user);
239239
assertEquals("_user", result._user);
240240
assertEquals("from$user", result.from$user);
@@ -274,7 +274,7 @@ public void testPascalCaseStandAlone()
274274
}
275275

276276
/**
277-
* [Issue#428]
277+
* For [databind#428]
278278
*/
279279
public void testIssue428PascalWithOverrides() throws Exception {
280280

@@ -288,15 +288,32 @@ public void testIssue428PascalWithOverrides() throws Exception {
288288
}
289289

290290
/**
291-
* For [Issue#461]
291+
* For [databind#461]
292292
*/
293293
public void testSimpleLowerCase() throws Exception
294294
{
295295
final BoringBean input = new BoringBean();
296-
ObjectMapper m = new ObjectMapper();
296+
ObjectMapper m = objectMapper();
297297

298298
assertEquals(aposToQuotes("{'firstname':'Bob','lastname':'Burger'}"),
299299
m.writeValueAsString(input));
300300
}
301-
}
302301

302+
/**
303+
* Test [databind#815], problems with ObjectNode, naming strategy
304+
*/
305+
public void testNamingWithObjectNode() throws Exception
306+
{
307+
ObjectMapper m = new ObjectMapper();
308+
m.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE);
309+
ClassWithObjectNodeField result =
310+
m.readValue(
311+
"{ \"id\": \"1\", \"json\": { \"foo\": \"bar\", \"baz\": \"bing\" } }",
312+
ClassWithObjectNodeField.class);
313+
assertNotNull(result);
314+
assertEquals("1", result.id);
315+
assertNotNull(result.json);
316+
assertEquals(2, result.json.size());
317+
assertEquals("bing", result.json.path("baz").asText());
318+
}
319+
}

0 commit comments

Comments
 (0)