Nested objects - leocadiotine/Dumbledroid GitHub Wiki

Dumbledroid can map JSON/XML nodes to primitive types in Java. But beyond that, it also supports nested objects. This page aims to explain this and tell how to use this feature.

##In practice Let's see a code excerpt from DumbledroidExample that shows what is a nested object and how to parse them using Dumbledroid.

Suppose you have a XML like this:

<sith>
	<kills>354</kills>
	<suit>
		<color>Black</color>
		<cloak>true</cloak>
	</suit>
</sith>

<kills> is an int. But <suit> is a more complex object, with its own attributes. To parse an object like this using Dumbledroid, you need to write two classes:

One for <sith>:

public class Sith extends AbstractModel {

	private int kills;
	private Suit suit;

	
	public Sith() {
		super(SITH_URL);
	}
	
	@Override
	protected DataType getDataType() {
		return DataType.XML;
	}
}

…and another for <suit>:

public class Suit implements Serializable {

	private String color;
	private boolean cloak;
}

Notice that Suit doesn't need to extend AbstractModel. The only requirement is that it implements the Serializable interface for the cache to work.

⚠️ **GitHub.com Fallback** ⚠️