Class GsonResourceCodec<R>
java.lang.Object
com.inductiveautomation.ignition.gateway.config.GsonResourceCodec<R>
- All Implemented Interfaces:
JsonResourceCodec<R>
,ResourceCodec<R>
A ResourceCodec that uses a Gson instance to directly encode and decode resources.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.inductiveautomation.ignition.common.gson.Gson
protected final ResourceValidator<R>
-
Constructor Summary
ConstructorsConstructorDescriptionGsonResourceCodec
(Class<R> recordType, com.inductiveautomation.ignition.common.gson.Gson gson) GsonResourceCodec
(Class<R> recordType, com.inductiveautomation.ignition.common.gson.Gson gson, ResourceValidator<R> validator) -
Method Summary
Modifier and TypeMethodDescriptionstatic <R> GsonResourceCodec<R>
create
(Class<R> recordType, Consumer<com.inductiveautomation.ignition.common.gson.GsonBuilder> gsonBuilderCustomizer) decodeFromJson
(com.inductiveautomation.ignition.common.gson.JsonElement json) Similar toJsonResourceCodec.decode(Resource)
, but decodes the resource's config from a JSON element.decodeFromJson
(Reader reader) Similar toJsonResourceCodec.decode(Resource)
, but reads the resource's config from a reader which will contain the JSON data of the encoded config object.void
encode
(R config, ResourceBuilder builder) Encodes a resource's config object, and stores it in the resource in the appropriate location.com.inductiveautomation.ignition.common.gson.JsonElement
encodeToJson
(R resource) Converts a resource config object instance to a JSON representation.protected R
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.inductiveautomation.ignition.gateway.config.JsonResourceCodec
decode
Methods inherited from interface com.inductiveautomation.ignition.gateway.config.ResourceCodec
decodeIfValid
-
Field Details
-
recordType
-
gson
protected final com.inductiveautomation.ignition.common.gson.Gson gson -
validator
-
-
Constructor Details
-
GsonResourceCodec
-
GsonResourceCodec
public GsonResourceCodec(Class<R> recordType, com.inductiveautomation.ignition.common.gson.Gson gson, @Nullable ResourceValidator<R> validator)
-
-
Method Details
-
encode
Description copied from interface:ResourceCodec
Encodes a resource's config object, and stores it in the resource in the appropriate location.- Specified by:
encode
in interfaceResourceCodec<R>
-
encodeToJson
Description copied from interface:JsonResourceCodec
Converts a resource config object instance to a JSON representation.- Specified by:
encodeToJson
in interfaceJsonResourceCodec<R>
- Parameters:
resource
- The resource to convert.- Returns:
- A JSON representation of the resource.
-
decodeFromJson
Description copied from interface:JsonResourceCodec
Similar toJsonResourceCodec.decode(Resource)
, but reads the resource's config from a reader which will contain the JSON data of the encoded config object.- Specified by:
decodeFromJson
in interfaceJsonResourceCodec<R>
- Throws:
DecodingException
-
decodeFromJson
public R decodeFromJson(com.inductiveautomation.ignition.common.gson.JsonElement json) throws DecodingException Description copied from interface:JsonResourceCodec
Similar toJsonResourceCodec.decode(Resource)
, but decodes the resource's config from a JSON element.- Specified by:
decodeFromJson
in interfaceJsonResourceCodec<R>
- Throws:
DecodingException
-
validate
- Throws:
ValidationException
-
create
public static <R> GsonResourceCodec<R> create(Class<R> recordType, @Nullable Consumer<com.inductiveautomation.ignition.common.gson.GsonBuilder> gsonBuilderCustomizer)
-