Package org.forgerock.api.jackson
Class JacksonUtils
- java.lang.Object
-
- org.forgerock.api.jackson.JacksonUtils
-
public final class JacksonUtils extends Object
Some utilities for dealing with Jackson schemas.
-
-
Field Summary
Fields Modifier and Type Field Description static com.fasterxml.jackson.databind.ObjectMapperOBJECT_MAPPERA public staticObjectMapperinstance, so that they do not have to be instantiated all over the place, as they are expensive to construct.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.module.jsonSchema.JsonSchemaschemaFor(Class<?> type)Obtain the JsonSchema for a type, using the extended schema classes that are in this package.static booleanvalidateJsonToSchema(String json, com.fasterxml.jackson.module.jsonSchema.JsonSchema schema)Validate that the provided JSON conforms to the schema.
-
-
-
Field Detail
-
OBJECT_MAPPER
public static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
A public staticObjectMapperinstance, so that they do not have to be instantiated all over the place, as they are expensive to construct. Note that theSerializationFeature.WRITE_DATES_AS_TIMESTAMPSoption is disabled, so that dates will be in JSON Schema v4 format (e.g., "type":"string", "format":"date-time").
-
-
Method Detail
-
validateJsonToSchema
public static boolean validateJsonToSchema(String json, com.fasterxml.jackson.module.jsonSchema.JsonSchema schema) throws javax.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:
javax.validation.ValidationException- If the JSON does not conform to the schema.
-
schemaFor
public static com.fasterxml.jackson.module.jsonSchema.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.
-
-