Skip to content

Commit

Permalink
Fix #578 (@JsonAppend properties serialized twice) (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Mar 31, 2023
1 parent a18b8cd commit 099f91a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-dataformat-xml
=== Releases ===
------------------------------------------------------------------------

Not yet released

#578: `XmlMapper` serializes `@JsonAppend` property twice
(reported by @stepince)

2.15.0-rc2 (28-Mar-2023)

#286: Conflict between `@JsonIdentityInfo` and Unwrapped Lists
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.fasterxml.jackson.dataformat.xml;

import java.lang.annotation.Annotation;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.dataformat.xml.annotation.*;

/**
Expand Down Expand Up @@ -124,6 +126,19 @@ public String findNamespace(MapperConfig<?> config, Annotated ann)
return null;
}

/**
* Due to issue [dataformat-xml#578] need to suppress calls to this method
* to avoid duplicate virtual properties from being added. Not elegant
* but .. works.
*
* @since 2.15
*/
@Override
public void findAndAddVirtualProperties(MapperConfig<?> config, AnnotatedClass ac,
List<BeanPropertyWriter> properties) {
return;
}

/*
/**********************************************************************
/* XmlAnnotationIntrospector, isXxx methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.xml.failing;
package com.fasterxml.jackson.dataformat.xml.ser;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
Expand Down Expand Up @@ -53,6 +53,6 @@ public VirtualBeanPropertyWriter withConfig(MapperConfig<?> config, AnnotatedCla
// [dataformat-xml#578]: Duplication of virtual properties
public void testJsonAppend() throws Exception {
String xml = MAPPER.writeValueAsString(new Pojo578("foo"));
assertEquals("<Pojo><name>foo</name><virtual>bar</virtual></Pojo>",xml);
assertEquals("<Pojo578><name>foo</name><virtual>bar</virtual></Pojo578>",xml);
}
}

0 comments on commit 099f91a

Please sign in to comment.