Skip to content

Commit 1bed6c2

Browse files
committed
Fix #412 in master
1 parent f0a2158 commit 1bed6c2

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java

+16-36
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ public Version version() {
265265
* Method for constructing a new instance that is configured
266266
* with specified feature enabled.
267267
*/
268-
public ObjectWriter with(SerializationFeature feature)
269-
{
268+
public ObjectWriter with(SerializationFeature feature) {
270269
SerializationConfig newConfig = _config.with(feature);
271270
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
272271
}
@@ -275,9 +274,7 @@ public ObjectWriter with(SerializationFeature feature)
275274
* Method for constructing a new instance that is configured
276275
* with specified features enabled.
277276
*/
278-
public ObjectWriter with(SerializationFeature first,
279-
SerializationFeature... other)
280-
{
277+
public ObjectWriter with(SerializationFeature first, SerializationFeature... other) {
281278
SerializationConfig newConfig = _config.with(first, other);
282279
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
283280
}
@@ -286,8 +283,7 @@ public ObjectWriter with(SerializationFeature first,
286283
* Method for constructing a new instance that is configured
287284
* with specified features enabled.
288285
*/
289-
public ObjectWriter withFeatures(SerializationFeature... features)
290-
{
286+
public ObjectWriter withFeatures(SerializationFeature... features) {
291287
SerializationConfig newConfig = _config.withFeatures(features);
292288
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
293289
}
@@ -296,8 +292,7 @@ public ObjectWriter withFeatures(SerializationFeature... features)
296292
* Method for constructing a new instance that is configured
297293
* with specified feature enabled.
298294
*/
299-
public ObjectWriter without(SerializationFeature feature)
300-
{
295+
public ObjectWriter without(SerializationFeature feature) {
301296
SerializationConfig newConfig = _config.without(feature);
302297
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
303298
}
@@ -306,9 +301,7 @@ public ObjectWriter without(SerializationFeature feature)
306301
* Method for constructing a new instance that is configured
307302
* with specified features enabled.
308303
*/
309-
public ObjectWriter without(SerializationFeature first,
310-
SerializationFeature... other)
311-
{
304+
public ObjectWriter without(SerializationFeature first, SerializationFeature... other) {
312305
SerializationConfig newConfig = _config.without(first, other);
313306
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
314307
}
@@ -317,8 +310,7 @@ public ObjectWriter without(SerializationFeature first,
317310
* Method for constructing a new instance that is configured
318311
* with specified features enabled.
319312
*/
320-
public ObjectWriter withoutFeatures(SerializationFeature... features)
321-
{
313+
public ObjectWriter withoutFeatures(SerializationFeature... features) {
322314
SerializationConfig newConfig = _config.withoutFeatures(features);
323315
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
324316
}
@@ -331,8 +323,7 @@ public ObjectWriter withoutFeatures(SerializationFeature... features)
331323
* Note that the method does NOT change state of this reader, but
332324
* rather construct and returns a newly configured instance.
333325
*/
334-
public ObjectWriter with(DateFormat df)
335-
{
326+
public ObjectWriter with(DateFormat df) {
336327
SerializationConfig newConfig = _config.with(df);
337328
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
338329
}
@@ -341,29 +332,24 @@ public ObjectWriter with(DateFormat df)
341332
* Method that will construct a new instance that will use the default
342333
* pretty printer for serialization.
343334
*/
344-
public ObjectWriter withDefaultPrettyPrinter()
345-
{
335+
public ObjectWriter withDefaultPrettyPrinter() {
346336
return with(new DefaultPrettyPrinter());
347337
}
348338

349339
/**
350340
* Method that will construct a new instance that uses specified
351341
* provider for resolving filter instances by id.
352342
*/
353-
public ObjectWriter with(FilterProvider filterProvider)
354-
{
355-
if (filterProvider == _config.getFilterProvider()) { // no change?
356-
return this;
357-
}
358-
return new ObjectWriter(this, _config.withFilters(filterProvider));
343+
public ObjectWriter with(FilterProvider filterProvider) {
344+
return (filterProvider == _config.getFilterProvider()) ? this
345+
: new ObjectWriter(this, _config.withFilters(filterProvider));
359346
}
360347

361348
/**
362349
* Method that will construct a new instance that will use specified pretty
363350
* printer (or, if null, will not do any pretty-printing)
364351
*/
365-
public ObjectWriter with(PrettyPrinter pp)
366-
{
352+
public ObjectWriter with(PrettyPrinter pp) {
367353
if (pp == _prettyPrinter) {
368354
return this;
369355
}
@@ -383,8 +369,7 @@ public ObjectWriter with(PrettyPrinter pp)
383369
* Note that method does NOT change state of this reader, but
384370
* rather construct and returns a newly configured instance.
385371
*/
386-
public ObjectWriter withRootName(String rootName)
387-
{
372+
public ObjectWriter withRootName(String rootName) {
388373
SerializationConfig newConfig = _config.withRootName(rootName);
389374
return (newConfig == _config) ? this : new ObjectWriter(this, newConfig);
390375
}
@@ -397,8 +382,7 @@ public ObjectWriter withRootName(String rootName)
397382
* rather construct and returns a newly configured instance.
398383
*/
399384

400-
public ObjectWriter withSchema(FormatSchema schema)
401-
{
385+
public ObjectWriter withSchema(FormatSchema schema) {
402386
if (_schema == schema) {
403387
return this;
404388
}
@@ -415,8 +399,7 @@ public ObjectWriter withSchema(FormatSchema schema)
415399
* Note that method does NOT change state of this reader, but
416400
* rather construct and returns a newly configured instance.
417401
*/
418-
public ObjectWriter withType(JavaType rootType)
419-
{
402+
public ObjectWriter withType(JavaType rootType) {
420403
// 15-Mar-2013, tatu: Important! Indicate that static typing is needed:
421404
rootType = rootType.withStaticTyping();
422405
JsonSerializer<Object> rootSer = _prefetchRootSerializer(_config, rootType);
@@ -486,10 +469,7 @@ public ObjectWriter with(CharacterEscapes escapes) {
486469
* @since 2.3
487470
*/
488471
public ObjectWriter with(JsonFactory f) {
489-
if (f == _generatorFactory) {
490-
return this;
491-
}
492-
return new ObjectWriter(this, f);
472+
return (f == _generatorFactory) ? this : new ObjectWriter(this, f);
493473
}
494474

495475
/**

src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ public void serializeValue(JsonGenerator jgen, Object value, JavaType rootType,
218218
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
219219
if (wrap) {
220220
jgen.writeStartObject();
221-
jgen.writeFieldName(_rootNames.findRootName(value.getClass(), _config));
221+
jgen.writeFieldName((rootType == null)
222+
? _rootNames.findRootName(value.getClass(), _config)
223+
: _rootNames.findRootName(rootType, _config));
222224
}
223225
} else if (rootName.length() == 0) {
224226
wrap = false;

0 commit comments

Comments
 (0)