1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.logging.log4j.catalog.api.plugins;
17
18 import java.io.IOException;
19
20 import com.fasterxml.jackson.core.JsonParser;
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import com.fasterxml.jackson.databind.DeserializationContext;
23 import com.fasterxml.jackson.databind.JsonNode;
24 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
25 import org.apache.logging.log4j.catalog.api.ConstraintType;
26 import org.apache.logging.log4j.catalog.api.exception.NameNotFoundException;
27
28
29
30
31 public class ConstraintTypeDeserializer extends StdDeserializer<ConstraintType> {
32
33 ConstraintPlugins plugins = ConstraintPlugins.getInstance();
34
35 public ConstraintTypeDeserializer() {
36 this(null);
37 }
38
39 public ConstraintTypeDeserializer(Class<?> vc) {
40 super(vc);
41 }
42
43 @Override
44 public ConstraintType deserialize(JsonParser jp, DeserializationContext ctxt)
45 throws IOException, JsonProcessingException {
46 JsonNode node = jp.getCodec().readTree(jp);
47 String name = node.get("name").textValue();
48 ConstraintType type = plugins.findByName(name);
49 if (type == null) {
50 throw new NameNotFoundException("Unable to locate plugin for constraint type " + name);
51 }
52 return type;
53 }
54 }