Package net.solarnetwork.codec
Interface IndexedField
- All Known Implementing Classes:
BasicInstructionField,BasicInstructionStatusField,BasicLocationField,BasicObjectDatumStreamMetadataField
public interface IndexedField
API for a JSON field that is ordered by an index value for the purposes of
serialization.
This API is designed to be implemented by Enum types, to facilitate a
single definition of JSON object field names and their order when serializing
and deserializing a related object into/from JSON, without using reflection.
See
JsonUtils.parseIndexedFieldsObject(JsonParser, DeserializationContext, Object[], Map)
for help in parsing JSON using this structure. The intention is that a JSON
serializer and deserializer class pair would share a common Enum that
implements this interface to help ensure a consistent JSON structure is used
by both.
- Since:
- 1.72
- Version:
- 1.1
- Author:
- matt
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enum<E> & IndexedField>
Map<String,E> Get a mapping of field names toIndexedFieldinstances from an enumeration that implementsIndexedField.Get the field name.intgetIndex()Get the index.parseValue(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext ctxt) Parse a value from a parser.voidwriteValue(com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider, Object value) Write a value to a generator.
-
Method Details
-
getIndex
int getIndex()Get the index.- Returns:
- the index
-
getFieldName
String getFieldName()Get the field name.- Returns:
- the fieldName
-
parseValue
Object parseValue(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException, com.fasterxml.jackson.core.JsonProcessingException Parse a value from a parser.- Parameters:
parser- the parserctxt- the context- Returns:
- the parsed object
- Throws:
IOException- if any IO error occurscom.fasterxml.jackson.core.JsonProcessingException- if any JSON processing error occurs
-
writeValue
void writeValue(com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider, Object value) throws IOException, com.fasterxml.jackson.core.JsonProcessingException Write a value to a generator.- Parameters:
generator- the generatorprovider- the providervalue- the value to write- Throws:
IOException- if any IO error occurscom.fasterxml.jackson.core.JsonProcessingException- if any JSON processing error occurs
-
fieldMap
Get a mapping of field names toIndexedFieldinstances from an enumeration that implementsIndexedField.- Type Parameters:
E- the enum type- Parameters:
clazz- the enum class- Returns:
- the map
-