org.qi4j.valueserialization.stax

## Class StaxValueDeserializer

- java.lang.Object
- - org.qi4j.spi.value.ValueDeserializerAdapter<XMLEventReader,Node>
  - - org.qi4j.valueserialization.stax.StaxValueDeserializer

- All Implemented Interfaces:
    ValueDeserializer

      public class StaxValueDeserializer
      extends ValueDeserializerAdapter<XMLEventReader,Node>

  ValueDeserializer reading Values from XML documents.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.qi4j.spi.value.ValueDeserializerAdapter

      `ValueDeserializerAdapter.ComplexDeserializer<T,InputType,InputNodeType>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StaxValueDeserializer(Application application, Module module, ServiceReference<ValueDeserializer> serviceRef)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected XMLEventReader` | `adaptInput(InputStream input)` This method is always called first, this is a chance to wrap the input type.
    `protected Object` | `asSimpleValue(Node inputNode)`
    `protected <T> T` | `getObjectFieldValue(Node inputNode, String key, Function<Node,T> valueDeserializer)` Return null if the field do not exists.
    `protected boolean` | `isObjectValue(Node inputNode)`
    `protected boolean` | `objectHasField(Node inputNode, String key)`
    `protected <T> void` | `putArrayNodeInCollection(Node inputNode, Function<Node,T> deserializer, Collection<T> collection)`
    `protected <K,V> void` | `putArrayNodeInMap(Node inputNode, Function<Node,K> keyDeserializer, Function<Node,V> valueDeserializer, Map<K,V> map)`
    `protected <V> void` | `putObjectNodeInMap(Node inputNode, Function<Node,V> valueDeserializer, Map<String,V> map)`
    `protected <T> Collection<T>` | `readArrayInCollection(XMLEventReader input, Function<XMLEventReader,T> deserializer, Collection<T> collection)`
    `protected <K,V> Map<K,V>` | `readMapInMap(XMLEventReader input, Function<XMLEventReader,K> keyDeserializer, Function<XMLEventReader,V> valueDeserializer, Map<K,V> map)` A Map<K,V> is serialized in an array of entries objects.
    `protected Node` | `readObjectTree(XMLEventReader input)`
    `protected Object` | `readPlainValue(XMLEventReader input)`

    - ### Methods inherited from class org.qi4j.spi.value.ValueDeserializerAdapter

      `deserialize, deserialize, deserialize, deserialize, deserialize, deserialize, deserialize, onDeserializationEnd, onDeserializationStart, registerComplexDeserializer, registerDeserializer`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StaxValueDeserializer

          public StaxValueDeserializer(@Structure
                               Application application,
                               @Structure
                               Module module,
                               @Service
                               ServiceReference<ValueDeserializer> serviceRef)

  - ### Method Detail

    - #### adaptInput

          protected XMLEventReader adaptInput(InputStream input)
                                       throws Exception

      Description copied from class: `ValueDeserializerAdapter`
      This method is always called first, this is a chance to wrap the input type.
      Specified by:
        `adaptInput` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Parameters:
        `input` - InputStream to adapt
      Returns:
        Adapted input
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### readPlainValue

          protected Object readPlainValue(XMLEventReader input)
                                   throws Exception

      Specified by:
        `readPlainValue` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Parameters:
        `input` - Input
      Returns:
        a Plain Value read from the input
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### readArrayInCollection

          protected <T> Collection<T> readArrayInCollection(XMLEventReader input,
                                                Function<XMLEventReader,T> deserializer,
                                                Collection<T> collection)
                                                 throws Exception

      Specified by:
        `readArrayInCollection` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Type Parameters:
        `T` - Parameterized collection type
      Parameters:
        `input` - Input
        `deserializer` - Deserialization function
        `collection` - Collection
      Returns:
        The filled collection or null if no array
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### readMapInMap

          protected <K,V> Map<K,V> readMapInMap(XMLEventReader input,
                                    Function<XMLEventReader,K> keyDeserializer,
                                    Function<XMLEventReader,V> valueDeserializer,
                                    Map<K,V> map)
                                   throws Exception

      Description copied from class: `ValueDeserializerAdapter`
      A Map<K,V> is serialized in an array of entries objects.

      Here is an example in JSON:

           [
               { "key": "foo",       "value": "bar"   },
               { "key": "cathedral", "value": "bazar" }
           ]

      And an empty Map:

          []

      This allow to use any type as keys and values while keeping the Map order at the cost of having non-predictible order of key/value inside an entry object.

      Specified by:
        `readMapInMap` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Type Parameters:
        `K` - Parameterized map key type
        `V` - Parameterized map value type
      Parameters:
        `input` - Input
        `keyDeserializer` - Map key deserialization function
        `valueDeserializer` - Map value deserialization function
        `map` - Map
      Returns:
        The filled map or null if no array
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### readObjectTree

          protected Node readObjectTree(XMLEventReader input)
                                 throws Exception

      Specified by:
        `readObjectTree` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Parameters:
        `input` - Input
      Returns:
        an InputNodeType or null if the value was null
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### asSimpleValue

          protected Object asSimpleValue(Node inputNode)
                                  throws Exception

      Specified by:
        `asSimpleValue` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`

    - #### isObjectValue

          protected boolean isObjectValue(Node inputNode)
                                   throws Exception

      Specified by:
        `isObjectValue` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`

    - #### objectHasField

          protected boolean objectHasField(Node inputNode,
                               String key)
                                    throws Exception

      Specified by:
        `objectHasField` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`

    - #### getObjectFieldValue

          protected <T> T getObjectFieldValue(Node inputNode,
                                  String key,
                                  Function<Node,T> valueDeserializer)
                                   throws Exception

      Description copied from class: `ValueDeserializerAdapter`
      Return null if the field do not exists.
      Specified by:
        `getObjectFieldValue` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Type Parameters:
        `T` - Parameterized object field value type
      Parameters:
        `inputNode` - Input Node
        `key` - Object key
        `valueDeserializer` - Deserialization function
      Returns:
        The value of the field.
      Throws:
        `Exception` - that will be wrapped in a `ValueSerializationException`

    - #### putArrayNodeInCollection

          protected <T> void putArrayNodeInCollection(Node inputNode,
                                          Function<Node,T> deserializer,
                                          Collection<T> collection)
                                           throws Exception

      Specified by:
        `putArrayNodeInCollection` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`

    - #### putArrayNodeInMap

          protected <K,V> void putArrayNodeInMap(Node inputNode,
                                     Function<Node,K> keyDeserializer,
                                     Function<Node,V> valueDeserializer,
                                     Map<K,V> map)
                                    throws Exception

      Specified by:
        `putArrayNodeInMap` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`

    - #### putObjectNodeInMap

          protected <V> void putObjectNodeInMap(Node inputNode,
                                    Function<Node,V> valueDeserializer,
                                    Map<String,V> map)
                                     throws Exception

      Specified by:
        `putObjectNodeInMap` in class `ValueDeserializerAdapter<XMLEventReader,Node>`
      Throws:
        `Exception`