use of com.fasterxml.jackson.databind.ObjectMapper in project ratpack by ratpack.
the class JsonParser method parse.
@Override
public <T> T parse(Context context, TypedData body, Parse<T, JsonParseOpts> parse) throws IOException {
if (!body.getContentType().isJson()) {
return null;
}
JsonParseOpts opts = parse.getOpts().orElse(DefaultJsonParseOpts.INSTANCE);
TypeToken<T> type = parse.getType();
ObjectMapper objectMapper = opts.getObjectMapper().orElseGet(() -> context.get(ObjectMapper.class));
InputStream inputStream = body.getInputStream();
if (type.equals(JSON_NODE_TYPE)) {
return cast(objectMapper.readTree(inputStream));
} else {
return objectMapper.readValue(inputStream, toJavaType(type, objectMapper));
}
}
use of com.fasterxml.jackson.databind.ObjectMapper in project ratpack by ratpack.
the class DefaultConfigDataBuilder method newDefaultObjectMapper.
public static ObjectMapper newDefaultObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.registerModule(new Jdk8Module());
objectMapper.registerModule(new GuavaModule());
objectMapper.registerModule(new JavaTimeModule());
JsonFactory factory = objectMapper.getFactory();
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
return objectMapper;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project ratpack by ratpack.
the class AbstractPropertiesConfigSource method loadConfigData.
@Override
public ObjectNode loadConfigData(ObjectMapper objectMapper, FileSystemBinding fileSystemBinding) throws Exception {
ObjectNode rootNode = objectMapper.createObjectNode();
Properties properties = loadProperties();
Stream<Pair<String, String>> pairs = properties.stringPropertyNames().stream().map(key -> Pair.of(key, properties.getProperty(key)));
if (prefix.isPresent()) {
pairs = pairs.filter(p -> p.left.startsWith(prefix.get())).map(((Function<Pair<String, String>, Pair<String, String>>) p -> p.mapLeft(s -> s.substring(prefix.get().length()))).toFunction());
}
pairs.forEach(p -> populate(rootNode, p.left, p.right));
return rootNode;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class CookieDeserializer method deserialize.
@Override
public Cookie deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode jsonNode = mapper.readTree(jp);
Cookie cookie = new Cookie(readJsonNode(jsonNode, "name").asText(), readJsonNode(jsonNode, "value").asText());
cookie.setComment(readJsonNode(jsonNode, "comment").asText());
cookie.setDomain(readJsonNode(jsonNode, "domain").asText());
cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
cookie.setVersion(readJsonNode(jsonNode, "version").asInt());
cookie.setPath(readJsonNode(jsonNode, "path").asText());
cookie.setHttpOnly(readJsonNode(jsonNode, "httpOnly").asBoolean());
return cookie;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class PreAuthenticatedAuthenticationTokenDeserializer method deserialize.
/**
* This method construct {@link PreAuthenticatedAuthenticationToken} object from serialized json.
* @param jp the JsonParser
* @param ctxt the DeserializationContext
* @return the user
* @throws IOException if a exception during IO occurs
* @throws JsonProcessingException if an error during JSON processing occurs
*/
@Override
public PreAuthenticatedAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
PreAuthenticatedAuthenticationToken token = null;
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode jsonNode = mapper.readTree(jp);
Boolean authenticated = readJsonNode(jsonNode, "authenticated").asBoolean();
JsonNode principalNode = readJsonNode(jsonNode, "principal");
Object principal = null;
if (principalNode.isObject()) {
principal = mapper.readValue(principalNode.toString(), new TypeReference<User>() {
});
} else {
principal = principalNode.asText();
}
Object credentials = readJsonNode(jsonNode, "credentials").asText();
List<GrantedAuthority> authorities = mapper.readValue(readJsonNode(jsonNode, "authorities").toString(), new TypeReference<List<GrantedAuthority>>() {
});
if (authenticated) {
token = new PreAuthenticatedAuthenticationToken(principal, credentials, authorities);
} else {
token = new PreAuthenticatedAuthenticationToken(principal, credentials);
}
token.setDetails(readJsonNode(jsonNode, "details"));
return token;
}
Aggregations