Class JsonFieldFormat
- java.lang.Object
-
- org.beanio.internal.parser.format.json.JsonFieldFormat
-
- All Implemented Interfaces:
FieldFormat,JsonNode
public class JsonFieldFormat extends java.lang.Object implements FieldFormat, JsonNode
AFieldFormatimplementation for a field in a JSON formatted record.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description JsonFieldFormat()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringextract(UnmarshallingContext context, boolean reportErrors)Extracts the field text from a record.intgetJsonArrayIndex()Returns the index of this node in its parent array, or -1 if not applicable (i.e.java.lang.StringgetJsonName()Returns the JSON field name.chargetJsonType()Returns the type of node.java.lang.StringgetName()Returns the field name.FieldPaddinggetPadding()intgetSize()Returns the size of the field.voidinsertField(MarshallingContext context, java.lang.String text)Inserts field text into a record.booleaninsertValue(MarshallingContext context, java.lang.Object value)Inserts a value into a record.booleanisBypassTypeHandler()booleanisJsonArray()Returns whether this node is a JSON array.booleanisLazy()TODO rename isLazy to something better?? Returns whether this field is optionally present in the record.booleanisNillable()Returns whether this field is nillable.voidsetBypassTypeHandler(boolean bypassTypeHandler)voidsetJsonArray(boolean repeating)voidsetJsonArrayIndex(int jsonArrayIndex)voidsetJsonName(java.lang.String jsonName)voidsetJsonType(char jsonType)voidsetLazy(boolean lazy)voidsetName(java.lang.String name)voidsetNillable(boolean nillable)voidsetPadding(FieldPadding padding)java.lang.StringtoString()
-
-
-
Method Detail
-
extract
public java.lang.String extract(UnmarshallingContext context, boolean reportErrors)
Description copied from interface:FieldFormatExtracts the field text from a record. Returnsnullif the field was not present in the record.May return
Value.INVALIDif the field is invalid, orValue.NILif 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:
extractin interfaceFieldFormat- Parameters:
context- theUnmarshallingContextholding the record- Returns:
- the field text
-
insertValue
public boolean insertValue(MarshallingContext context, java.lang.Object value)
Description copied from interface:FieldFormatInserts a value into a record. This method is called before type conversion. If the method returns false, type conversion is invoked andFieldFormat.insertField(MarshallingContext, String)is called. If the method returns true,FieldFormat.insertField(MarshallingContext, String)is not invoked.- Specified by:
insertValuein interfaceFieldFormat- Parameters:
context- theMarshallingContextvalue- 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, java.lang.String text)
Description copied from interface:FieldFormatInserts field text into a record.- Specified by:
insertFieldin interfaceFieldFormat- Parameters:
context- theMarshallingContextholding the recordtext- the field text to insert into the record
-
getName
public java.lang.String getName()
Description copied from interface:JsonNodeReturns the field name.
-
setName
public void setName(java.lang.String name)
- Parameters:
name-
-
setLazy
public void setLazy(boolean lazy)
- Parameters:
lazy-
-
getSize
public int getSize()
Description copied from interface:FieldFormatReturns the size of the field. Fixed length formats should return the field length, while other formats should simply return 1.- Specified by:
getSizein interfaceFieldFormat- Returns:
- the size of the field
-
setNillable
public void setNillable(boolean nillable)
- Parameters:
nillable-
-
isNillable
public boolean isNillable()
Description copied from interface:FieldFormatReturns whether this field is nillable.- Specified by:
isNillablein interfaceFieldFormat- Specified by:
isNillablein interfaceJsonNode- Returns:
- true if nillable, false otherwise
-
isLazy
public boolean isLazy()
Description copied from interface:FieldFormatTODO rename isLazy to something better?? Returns whether this field is optionally present in the record.- Specified by:
isLazyin interfaceFieldFormat- Returns:
- true if lazy, false otherwise
-
setJsonName
public void setJsonName(java.lang.String jsonName)
- Parameters:
jsonName-
-
getJsonName
public java.lang.String getJsonName()
Description copied from interface:JsonNodeReturns the JSON field name.- Specified by:
getJsonNamein interfaceJsonNode- Returns:
- the JSON field name
-
setJsonType
public void setJsonType(char jsonType)
- Parameters:
jsonType-
-
getJsonType
public char getJsonType()
Description copied from interface:JsonNodeReturns the type of node. IfJsonNode.isJsonArray()is true, this method returns the component type of the array.- Specified by:
getJsonTypein interfaceJsonNode- Returns:
- the node type
-
setJsonArray
public void setJsonArray(boolean repeating)
-
isJsonArray
public boolean isJsonArray()
Description copied from interface:JsonNodeReturns whether this node is a JSON array.- Specified by:
isJsonArrayin interfaceJsonNode- Returns:
- true if this node a JSON array, false otherwise
-
getJsonArrayIndex
public int getJsonArrayIndex()
Description copied from interface:JsonNodeReturns the index of this node in its parent array, or -1 if not applicable (i.e. its parent is an object).- Specified by:
getJsonArrayIndexin interfaceJsonNode- 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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-