[IMPLICIT] Ignore the field name of the list

Aug 14, 2012 at 10:31 PM
Edited Aug 14, 2012 at 10:34 PM

In Java world with XStream lib there is possiblity to ignore the field name (content) of the list. For example : 

@XStreamAlias("message")
class RendezvousMessage {

	@XStreamAlias("type")
	private int messageType;        
	
	private List<String> content;
	
	public RendezvousMessage(int messageType, String ... content) {
		this.messageType = messageType;
		this.content = Arrays.asList(content);
	}
	
}

Which results with following XML :

<message>
  <type>15</type>
  <content class="java.util.Arrays$ArrayList">
    <a class="string-array">
      <string>firstPart</string>
      <string>secondPart</string>
    </a>
  </content>
</message>

This is not what we desire therefore we will annotate the content list to be recognized as an implicit collection, so we will put XStreamImplicit above List<> and resulting XML will be :

<message>
  <type>15</type>
  <a class="string-array">
    <string>firstPart</string>
    <string>secondPart</string>
  </a>
</message>

Now without <content> element.

Sorry because of comparasion with the another library, but my question is, is that possible to do with YAXLib. If yes, how ?

Thank you!

Aug 14, 2012 at 10:42 PM
Edited Aug 14, 2012 at 10:42 PM

[YAXCollection(YAXCollectionSerializationTypes.RecursiveWithNoContainingElement)]

is what I was looking for! Next time I will do more research over the documentation before asking the question :)

 

Thank you!