use of com.fasterxml.jackson.core.TreeNode in project eventapis by kloiasoft.
the class RollbackCommandSpec method rollback.
default void rollback(CommandRecord record) {
// Get from context
ObjectMapper objectMapper = new ObjectMapper();
for (Method method : this.getClass().getDeclaredMethods()) {
if (method.getName().equals("rollback")) {
if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == CommandRecord.class)
continue;
try {
Object[] args = new Object[method.getParameterCount()];
for (Map.Entry<Integer, ?> entry : record.getParameters().entrySet()) {
Class<?> type = method.getParameterTypes()[entry.getKey()];
args[entry.getKey()] = objectMapper.treeToValue((TreeNode) entry.getValue(), type);
}
method.invoke(this, args);
} catch (InvocationTargetException | IllegalAccessException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
}
use of com.fasterxml.jackson.core.TreeNode in project bson4jackson by michel-kraemer.
the class BsonJavaScriptDeserializer method deserialize.
@Override
@SuppressWarnings("deprecation")
public JavaScript deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
if (jp instanceof BsonParser) {
BsonParser bsonParser = (BsonParser) jp;
if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || (bsonParser.getCurrentBsonType() != BsonConstants.TYPE_JAVASCRIPT && bsonParser.getCurrentBsonType() != BsonConstants.TYPE_JAVASCRIPT_WITH_SCOPE)) {
throw ctxt.mappingException(JavaScript.class);
}
return (JavaScript) bsonParser.getEmbeddedObject();
} else {
TreeNode tree = jp.getCodec().readTree(jp);
String code = null;
TreeNode codeNode = tree.get("$code");
if (codeNode instanceof ValueNode) {
code = ((ValueNode) codeNode).asText();
}
Map<String, Object> scope = null;
TreeNode scopeNode = tree.get("$scope");
if (scopeNode instanceof ObjectNode) {
@SuppressWarnings("unchecked") Map<String, Object> scope2 = jp.getCodec().treeToValue(scopeNode, Map.class);
scope = scope2;
}
return new JavaScript(code, scope);
}
}
use of com.fasterxml.jackson.core.TreeNode in project bson4jackson by michel-kraemer.
the class BsonRegexDeserializer method deserialize.
@Override
@SuppressWarnings("deprecation")
public Pattern deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
if (jp instanceof BsonParser) {
BsonParser bsonParser = (BsonParser) jp;
if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_REGEX) {
throw ctxt.mappingException(Pattern.class);
}
return (Pattern) bsonParser.getEmbeddedObject();
} else {
TreeNode tree = jp.getCodec().readTree(jp);
String pattern = null;
TreeNode patternNode = tree.get("$pattern");
if (patternNode instanceof ValueNode) {
pattern = ((ValueNode) patternNode).asText();
}
int flags = 0;
TreeNode flagsNode = tree.get("$flags");
if (flagsNode instanceof ValueNode) {
flags = ((ValueNode) flagsNode).asInt();
}
return Pattern.compile(pattern, flags);
}
}
use of com.fasterxml.jackson.core.TreeNode in project keycloak by keycloak.
the class ClaimInformationPointProviderTest method testBodyJsonClaimsInformationPoint.
@Test
public void testBodyJsonClaimsInformationPoint() throws Exception {
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", Arrays.asList("application/json"));
ObjectMapper mapper = JsonSerialization.mapper;
JsonParser parser = mapper.getFactory().createParser("{\"a\": {\"b\": {\"c\": \"c-value\"}}, \"d\": [\"d-value1\", \"d-value2\"], \"e\": {\"number\": 123}}");
TreeNode treeNode = mapper.readTree(parser);
HttpFacade httpFacade = createHttpFacade(headers, new ByteArrayInputStream(treeNode.toString().getBytes()));
Map<String, List<String>> claims = getClaimInformationProviderForPath("/claims-provider", "claims").resolve(httpFacade);
assertEquals("c-value", claims.get("claim-from-json-body-object").get(0));
assertEquals("d-value2", claims.get("claim-from-json-body-array").get(0));
assertEquals("123", claims.get("claim-from-json-body-number").get(0));
}
Aggregations