com.stanfy.gsonxml
Class GsonXmlBuilder

java.lang.Object
  extended by com.stanfy.gsonxml.GsonXmlBuilder

public class GsonXmlBuilder
extends java.lang.Object

Use this builder for constructing GsonXml object. All methods are very similar to GsonBuilder.


Constructor Summary
GsonXmlBuilder()
           
 
Method Summary
 GsonXml create()
          Creates a GsonXml instance based on the current configuration.
 GsonXmlBuilder setPrimitiveArrays(boolean primitiveArrays)
          If set to true than arrays can contain primitive values.
 GsonXmlBuilder setRootArrayPrimitive(boolean rootArrayPrimitive)
          When set to true and the root element is parsed as a collection this collection items are treated as primitives.
 GsonXmlBuilder setSameNameLists(boolean value)
          Here's the difference.
Same name lists: on
 GsonXmlBuilder setSkipRoot(boolean value)
          Here's the difference.
Skip root: on
 GsonXmlBuilder setTreatNamespaces(boolean value)
          Here's the difference.
Treat namespaces: on
 GsonXmlBuilder setXmlParserCreator(XmlParserCreator xmlParserCreator)
          Set a factory for XML pull parser.
 GsonXmlBuilder wrap(com.google.gson.GsonBuilder gsonBuilder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GsonXmlBuilder

public GsonXmlBuilder()
Method Detail

wrap

public GsonXmlBuilder wrap(com.google.gson.GsonBuilder gsonBuilder)
Parameters:
gsonBuilder - instance of GsonBuilder
Returns:
this instance for chaining

setXmlParserCreator

public GsonXmlBuilder setXmlParserCreator(XmlParserCreator xmlParserCreator)
Set a factory for XML pull parser.

Parameters:
xmlParserCreator - instance of XmlParserCreator
Returns:
this instance for chaining

setSkipRoot

public GsonXmlBuilder setSkipRoot(boolean value)
Here's the difference.
Skip root: on
   <root><name>value</name></root>
   ==>
   {name : 'value'}
 
Skip root: off
   <root><name>value</name></root>
   ==>
   {root : {name : 'value'}}
 

Parameters:
value - true to skip root element
Returns:
this instance for chaining

setTreatNamespaces

public GsonXmlBuilder setTreatNamespaces(boolean value)
Here's the difference.
Treat namespaces: on
   <root><ns:name>value</ns:name></root>
   ==>
   {'<ns>name' : 'value'}
 
Treat namespaces: off
   <root><ns:name>value</ns:name></root>
   ==>
   {name : 'value'}
 

Parameters:
value - true to treat namespaces
Returns:
this instance for chaining

setSameNameLists

public GsonXmlBuilder setSameNameLists(boolean value)
Here's the difference.
Same name lists: on
   <root>
     <name>value</name>
     <item>value1</item>
     <item>value2</item>
   </root>
   ==>
   {name : 'value', item : ['value1', 'value2']}
 
Treat namespaces: off
   <root>
     <name>value</name>
     <items>
       <ignored>value1</ignored>
       <ignored>value2</ignored>
     </items>
   </root>
   ==>
   {name : 'value', items : ['value1', 'value2']}
 

Parameters:
value - true for same name list policy
Returns:
this instance for chaining

setPrimitiveArrays

public GsonXmlBuilder setPrimitiveArrays(boolean primitiveArrays)
If set to true than arrays can contain primitive values. If false only arrays can contain objects only. When set to true you cannot parse the next sample:
   <list>
     <item>
       text node value
       <field-name>field value</field-name>
     </item>
     <item>value2</item>
   </list>
 
It's caused by the fact that parser meats 'text node value' and makes a decision that this item is primitive.

Parameters:
primitiveArrays - value for primitive arrays policy
Returns:
this instance for chaining

setRootArrayPrimitive

public GsonXmlBuilder setRootArrayPrimitive(boolean rootArrayPrimitive)
When set to true and the root element is parsed as a collection this collection items are treated as primitives.

Parameters:
rootArrayPrimitive - flag for 'root array primitive' policy
Returns:
this instance for chaining
See Also:
setPrimitiveArrays(boolean)

create

public GsonXml create()
Creates a GsonXml instance based on the current configuration. This method is free of side-effects to this GsonXmlBuilder instance and hence can be called multiple times.

Returns:
an instance of GsonXml configured with the options currently set in this builder