Package com.sap.cds
Interface CdsJsonConverter
@Beta
public interface CdsJsonConverter
Converts JSON data to and from CDS (Core Data Services) data structures.
Provides methods for serializing and deserializing JSON objects and arrays, as well as validating data against CDS types.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder interface for configuring and building aCdsJsonConverterinstance.static enumEnum defining the serialization of CDS Decimal types to JSON.static interfaceFactory interface for creatingCdsJsonConverter.Builderinstances.static enumDefines how to handle JSON properties not declared in the CDS type. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CdsJsonConverter.FactoryThe factory instance for creatingCdsJsonConverter.Builderinstances. -
Method Summary
Modifier and TypeMethodDescriptionstatic CdsJsonConverter.BuilderCreates a new builder for configuring and building aCdsJsonConverter.fromJsonArray(String jsonArray, CdsStructuredType type) Parses a JSON array string into a list ofCdsDatausing the given CDS structured type.fromJsonArray(String jsonArray, Class<T> type) Parses a JSON array string into a list of the givenCdsDatasubtype.fromJsonObject(String jsonObject, CdsStructuredType type) Parses a JSON object string intoCdsDatausing the given CDS structured type.<T extends CdsData>
TfromJsonObject(String jsonObject, Class<T> type) Parses a JSON object string into the givenCdsDatasubtype.Serializes a list ofMapinstances to a JSON array string.Serializes aMapinstance to a JSON object string.
-
Field Details
-
factory
The factory instance for creatingCdsJsonConverter.Builderinstances.
-
-
Method Details
-
fromJsonObject
Parses a JSON object string intoCdsDatausing the given CDS structured type.- Parameters:
jsonObject- JSON object as string (not null)type- CDS structured type (not null)- Returns:
- parsed
CdsData - Throws:
CdsJsonConverterException- if parsing or mapping fails
-
fromJsonObject
Parses a JSON object string into the givenCdsDatasubtype.- Type Parameters:
T- target CDS data type- Parameters:
jsonObject- JSON object as string (not null)type- target class (not null)- Returns:
- parsed instance of
type - Throws:
CdsJsonConverterException- if parsing or mapping failsCdsDefinitionNotFoundException- if the CDS type is unknown
-
fromJsonArray
Parses a JSON array string into a list ofCdsDatausing the given CDS structured type.- Parameters:
jsonArray- JSON array as string (not null)type- CDS structured type (not null)- Returns:
- list of parsed
CdsData - Throws:
CdsJsonConverterException- if parsing or mapping fails
-
fromJsonArray
Parses a JSON array string into a list of the givenCdsDatasubtype.- Type Parameters:
T- target CDS data type- Parameters:
jsonArray- JSON array as string (not null)type- target class (not null)- Returns:
- list of parsed instances of
type - Throws:
CdsJsonConverterException- if parsing or mapping failsCdsDefinitionNotFoundException- if the CDS type is unknown
-
toJson
Serializes aMapinstance to a JSON object string.- Parameters:
data- map instance to serialize (not null)- Returns:
- JSON object as string
- Throws:
CdsJsonConverterException- if serialization fails
-
toJson
Serializes a list ofMapinstances to a JSON array string.- Parameters:
data- list of instances to serialize (not null)- Returns:
- JSON array as string
- Throws:
CdsJsonConverterException- if serialization fails
-
builder
Creates a new builder for configuring and building aCdsJsonConverter.- Parameters:
model- theCdsModelto be used for validation during conversion- Returns:
- a new
CdsJsonConverter.Builderinstance - Throws:
CdsJsonConverterException- in case of an error
-