Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Fix #40: XmlElementRef ignored if inside XmlElementWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 23, 2015
1 parent fed1c88 commit a76a830
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-module-jaxb-annotations
=== Releases ===
------------------------------------------------------------------------

2.5.3 (not yet released)

#40: XmlElementRef ignored if inside XmlElementWrapper
(reported by gkresic@github)

2.5.2 (29-Mar-2015)

No changes since 2.5.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,17 +1235,9 @@ private static PropertyName findJaxbPropertyName(Annotated ae, Class<?> aeType,
if (element != null) {
return _combineNames(element.name(), element.namespace(), defaultName);
}
/* 11-Sep-2012, tatu: Wrappers should not be automatically used for renaming.
* At least not here (databinding core can do it if feature enabled).
*/
/*
XmlElementWrapper elementWrapper = ae.getAnnotation(XmlElementWrapper.class);
if (elementWrapper != null) {
return _combineNames(elementWrapper.name(), elementWrapper.namespace(), defaultName);
}
*/
XmlElementRef elementRef = ae.getAnnotation(XmlElementRef.class);
if (elementRef != null) {
boolean hasAName = (elementRef != null);
if (hasAName) {
if (!MARKER_FOR_DEFAULT.equals(elementRef.name())) {
return _combineNames(elementRef.name(), elementRef.namespace(), defaultName);
}
Expand All @@ -1261,9 +1253,14 @@ private static PropertyName findJaxbPropertyName(Annotated ae, Class<?> aeType,
}
}
}
if (!hasAName) {
hasAName = ae.hasAnnotation(XmlElementWrapper.class);
}
// 09-Aug-2014, tatu: Note: prior to 2.4.2, we used to give explicit name "value"
// if there was "@XmlValue" annotation; since then, only implicit name.
return null;

// One more thing:
return hasAName ? PropertyName.USE_DEFAULT : null;
}

private static PropertyName _combineNames(String localName, String namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

public class DataHandlerJsonSerializer extends StdSerializer<DataHandler>
{
private static final long serialVersionUID = 1L;

public DataHandlerJsonSerializer() { super(DataHandler.class); }

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public class DomElementJsonSerializer
extends StdSerializer<Element>
{
private static final long serialVersionUID = 1L;

public DomElementJsonSerializer() { super(Element.class); }

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.module.jaxb.introspect;

import java.util.Date;
import java.util.*;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlAdapter;
Expand Down Expand Up @@ -54,7 +54,21 @@ public Date unmarshal(String arg0) throws Exception {
return new Date(Long.parseLong(arg0));
}
}


// [jaxb-annotations#40]: Need to recognize more marker annotations
@XmlAccessorType(XmlAccessType.NONE)
public class Bean40
{
@XmlElement
public int getA() { return 1; }

@XmlElementWrapper(name="b")
public int getX() { return 2; }

@XmlElementRef
public int getC() { return 3; }
}

/*
/**********************************************************
/* Unit tests
Expand Down Expand Up @@ -89,4 +103,18 @@ public void testForJackson288() throws Exception
assertNotNull(d);
assertEquals(TIMESTAMP, d.getTime());
}

public void testInclusionIssue40() throws Exception
{
ObjectMapper mapper = getJaxbMapper();
mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
String json = mapper.writeValueAsString(new Bean40());
@SuppressWarnings("unchecked")
Map<String,Object> map = mapper.readValue(json, Map.class);
Map<String,Object> exp = new LinkedHashMap<String,Object>();
exp.put("a", Integer.valueOf(1));
exp.put("b", Integer.valueOf(2));
exp.put("c", Integer.valueOf(3));
assertEquals(exp, map);
}
}

0 comments on commit a76a830

Please sign in to comment.