Package org.forgerock.api.jackson
Class JacksonUtils
java.lang.Object
org.forgerock.api.jackson.JacksonUtils
Some utilities for working with Jackson, JSON object mapping, and JSON schema.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.fasterxml.jackson.databind.ObjectMapperA public staticObjectMapperinstance, so that they do not have to be instantiated all over the place, as they are expensive to construct. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.ObjectMapperCreate a Jackson JSON object mapper that is best-suited for general-purpose use by documentation and tests.static com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchemaObtain the JsonSchema for a type, using the extended schema classes that are in this package.static booleanvalidateJsonToSchema(String json, com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchema schema) Validate that the provided JSON conforms to the schema.
-
Field Details
-
OBJECT_MAPPER
A public staticObjectMapperinstance, so that they do not have to be instantiated all over the place, as they are expensive to construct.
-
-
Method Details
-
createGenericMapper
Create a Jackson JSON object mapper that is best-suited for general-purpose use by documentation and tests.The new mapper is configured separately from the mapper used by
OBJECT_MAPPER; it does not include any of the normal customizations for OpenAPI. This ensures that the JSON output is a reliable representation of each object, without any of the tweaks that are normally needed for OpenAPI output.- Returns:
- A Jackson
ObjectMapperthat can generically handle most POJOs and localize-able strings.
-
validateJsonToSchema
public static boolean validateJsonToSchema(String json, com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchema schema) throws jakarta.validation.ValidationException Validate that the provided JSON conforms to the schema.- Parameters:
json- JSON content.schema- The schema. Must be an instance of one of the extended schema classes in this package.- Returns:
trueif schema implementsValidatableSchemaand was validated andfalseotherwise- Throws:
jakarta.validation.ValidationException- If the JSON does not conform to the schema.
-
schemaFor
public static com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchema schemaFor(Class<?> type) throws com.fasterxml.jackson.databind.JsonMappingException Obtain the JsonSchema for a type, using the extended schema classes that are in this package.- Parameters:
type- The class to get a schema for.- Returns:
- The schema.
- Throws:
com.fasterxml.jackson.databind.JsonMappingException- If the type cannot be mapped to a schema by Jackson.
-