BeanIO 2.0.4

org.beanio.internal.parser.format.json
Class JsonFieldFormat

java.lang.Object
  extended by org.beanio.internal.parser.format.json.JsonFieldFormat
All Implemented Interfaces:
FieldFormat, JsonNode

public class JsonFieldFormat
extends Object
implements FieldFormat, JsonNode

A FieldFormat implementation for a field in a JSON formatted record.

Since:
2.0
Author:
Kevin Seim

Field Summary
 
Fields inherited from interface org.beanio.internal.parser.format.json.JsonNode
ARRAY, BOOLEAN, NUMBER, OBJECT, STRING
 
Constructor Summary
JsonFieldFormat()
          Constructs a new JsonFieldFormat.
 
Method Summary
 String extract(UnmarshallingContext context, boolean reportErrors)
          Extracts the field text from a record.
 int getJsonArrayIndex()
          Returns the index of this node in its parent array, or -1 if not applicable (i.e.
 String getJsonName()
          Returns the JSON field name.
 char getJsonType()
          Returns the type of node.
 String getName()
          Returns the field name.
 FieldPadding getPadding()
           
 int getSize()
          Returns the size of the field.
 void insertField(MarshallingContext context, String text)
          Inserts field text into a record.
 boolean insertValue(MarshallingContext context, Object value)
          Inserts a value into a record.
 boolean isBypassTypeHandler()
           
 boolean isJsonArray()
          Returns whether this node is a JSON array.
 boolean isLazy()
          TODO rename isLazy to something better?? Returns whether this field is optionally present in the record.
 boolean isNillable()
          Returns whether this field is nillable.
 void setBypassTypeHandler(boolean bypassTypeHandler)
           
 void setJsonArray(boolean repeating)
           
 void setJsonArrayIndex(int jsonArrayIndex)
           
 void setJsonName(String jsonName)
           
 void setJsonType(char jsonType)
           
 void setLazy(boolean lazy)
           
 void setName(String name)
           
 void setNillable(boolean nillable)
           
 void setPadding(FieldPadding padding)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonFieldFormat

public JsonFieldFormat()
Constructs a new JsonFieldFormat.

Method Detail

extract

public String extract(UnmarshallingContext context,
                      boolean reportErrors)
Description copied from interface: FieldFormat
Extracts the field text from a record. Returns null if the field was not present in the record.

May return Value.INVALID if the field is invalid, or Value.NIL if the field is explicitly set to nil or null such as in an XML or JSON formatted stream.

Implementations should also remove any field padding before returning the text.

Specified by:
extract in interface FieldFormat
Parameters:
context - the UnmarshallingContext holding the record
Returns:
the field text

insertValue

public boolean insertValue(MarshallingContext context,
                           Object value)
Description copied from interface: FieldFormat
Inserts a value into a record. This method is called before type conversion. If the method returns false, type conversion is invoked and FieldFormat.insertField(MarshallingContext, String) is called. If the method returns true, FieldFormat.insertField(MarshallingContext, String) is not invoked.

Specified by:
insertValue in interface FieldFormat
Parameters:
context - the MarshallingContext
value - the value to insert into the record
Returns:
true if type conversion is required and FieldFormat.insertField(MarshallingContext, String) must be invoked, false otherwise

insertField

public void insertField(MarshallingContext context,
                        String text)
Description copied from interface: FieldFormat
Inserts field text into a record.

Specified by:
insertField in interface FieldFormat
Parameters:
context - the MarshallingContext holding the record
text - the field text to insert into the record

getName

public String getName()
Description copied from interface: JsonNode
Returns the field name.

Specified by:
getName in interface JsonNode
Returns:
the field name

setName

public void setName(String name)
Parameters:
name -

setLazy

public void setLazy(boolean lazy)
Parameters:
lazy -

getSize

public int getSize()
Description copied from interface: FieldFormat
Returns the size of the field. Fixed length formats should return the field length, while other formats should simply return 1.

Specified by:
getSize in interface FieldFormat
Returns:
the size of the field

setNillable

public void setNillable(boolean nillable)
Parameters:
nillable -

isNillable

public boolean isNillable()
Description copied from interface: FieldFormat
Returns whether this field is nillable.

Specified by:
isNillable in interface FieldFormat
Specified by:
isNillable in interface JsonNode
Returns:
true if nillable, false otherwise

isLazy

public boolean isLazy()
Description copied from interface: FieldFormat
TODO rename isLazy to something better?? Returns whether this field is optionally present in the record.

Specified by:
isLazy in interface FieldFormat
Returns:
true if lazy, false otherwise

setJsonName

public void setJsonName(String jsonName)
Parameters:
jsonName -

getJsonName

public String getJsonName()
Description copied from interface: JsonNode
Returns the JSON field name.

Specified by:
getJsonName in interface JsonNode
Returns:
the JSON field name

setJsonType

public void setJsonType(char jsonType)
Parameters:
jsonType -

getJsonType

public char getJsonType()
Description copied from interface: JsonNode
Returns the type of node. If JsonNode.isJsonArray() is true, this method returns the component type of the array.

Specified by:
getJsonType in interface JsonNode
Returns:
the node type

setJsonArray

public void setJsonArray(boolean repeating)

isJsonArray

public boolean isJsonArray()
Description copied from interface: JsonNode
Returns whether this node is a JSON array.

Specified by:
isJsonArray in interface JsonNode
Returns:
true if this node a JSON array, false otherwise

getJsonArrayIndex

public int getJsonArrayIndex()
Description copied from interface: JsonNode
Returns the index of this node in its parent array, or -1 if not applicable (i.e. its parent is an object).

Specified by:
getJsonArrayIndex in interface JsonNode
Returns:
the index of this node in its parent array

setJsonArrayIndex

public void setJsonArrayIndex(int jsonArrayIndex)

getPadding

public FieldPadding getPadding()

setPadding

public void setPadding(FieldPadding padding)

isBypassTypeHandler

public boolean isBypassTypeHandler()

setBypassTypeHandler

public void setBypassTypeHandler(boolean bypassTypeHandler)

toString

public String toString()
Overrides:
toString in class Object

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim