File tree 4 files changed +47
-0
lines changed
main/java/com/fasterxml/jackson/databind
test/java/com/fasterxml/jackson/databind
4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ Project: jackson-databind
22
22
#737: Add support for writing raw values in TokenBuffer
23
23
(suggested by Guillaume S, gsmet@github)
24
24
#743: Add `RawValue` helper type, for piping raw values through `TokenBuffer`
25
+ #762: Add `ObjectWriter.withoutRootName()`, `ObjectReader.withoutRootName()`
25
26
#765: `SimpleType.withStaticTyping()` impl incorrect
26
27
- Remove old cglib compatibility tests; cause problems in Eclipse
27
28
Original file line number Diff line number Diff line change @@ -537,6 +537,20 @@ public ObjectReader withRootName(String rootName) {
537
537
return _with (_config .withRootName (rootName ));
538
538
}
539
539
540
+ /**
541
+ * Convenience method that is same as calling:
542
+ *<code>
543
+ * withRootName("")
544
+ *</code>
545
+ * which will forcibly prevent use of root name wrapping when writing
546
+ * values with this {@link ObjectReader}.
547
+ *
548
+ * @since 2.6
549
+ */
550
+ public ObjectReader withoutRootName () {
551
+ return _with (_config .withRootName ("" ));
552
+ }
553
+
540
554
/**
541
555
* Method for constructing a new instance with configuration that
542
556
* passes specified {@link FormatSchema} to {@link JsonParser} that
Original file line number Diff line number Diff line change @@ -402,12 +402,30 @@ public ObjectWriter with(PrettyPrinter pp) {
402
402
*<p>
403
403
* Note that method does NOT change state of this reader, but
404
404
* rather construct and returns a newly configured instance.
405
+ *
406
+ * @param rootName Root name to use, if non-empty; `null` for "use defaults",
407
+ * and empty String ("") for "do NOT add root wrapper"
405
408
*/
406
409
public ObjectWriter withRootName (String rootName ) {
407
410
SerializationConfig newConfig = _config .withRootName (rootName );
408
411
return (newConfig == _config ) ? this : _new (this , newConfig );
409
412
}
410
413
414
+ /**
415
+ * Convenience method that is same as calling:
416
+ *<code>
417
+ * withRootName("")
418
+ *</code>
419
+ * which will forcibly prevent use of root name wrapping when writing
420
+ * values with this {@link ObjectWriter}.
421
+ *
422
+ * @since 2.6
423
+ */
424
+ public ObjectWriter withoutRootName () {
425
+ SerializationConfig newConfig = _config .withRootName ("" );
426
+ return (newConfig == _config ) ? this : _new (this , newConfig );
427
+ }
428
+
411
429
/**
412
430
* Method that will construct a new instance that uses specific format schema
413
431
* for serialization.
Original file line number Diff line number Diff line change @@ -98,8 +98,22 @@ public void testRootUsingExplicitConfig() throws Exception
98
98
json = wrapping .writer ().withRootName ("" ).writeValueAsString (new Bean ());
99
99
assertEquals ("{\" a\" :3}" , json );
100
100
101
+ // 21-Apr-2015, tatu: Alternative available with 2.6 as well:
102
+ json = wrapping .writer ().withoutRootName ().writeValueAsString (new Bean ());
103
+ assertEquals ("{\" a\" :3}" , json );
104
+
101
105
bean = wrapping .reader (Bean .class ).withRootName ("" ).readValue (json );
102
106
assertNotNull (bean );
107
+ assertEquals (3 , bean .a );
108
+
109
+ bean = wrapping .reader (Bean .class ).withoutRootName ().readValue ("{\" a\" :4}" );
110
+ assertNotNull (bean );
111
+ assertEquals (4 , bean .a );
112
+
113
+ // and back to defaults
114
+ bean = wrapping .reader (Bean .class ).readValue ("{\" rudy\" :{\" a\" :7}}" );
115
+ assertNotNull (bean );
116
+ assertEquals (7 , bean .a );
103
117
}
104
118
105
119
/*
You can’t perform that action at this time.
0 commit comments