use of de.undercouch.bson4jackson.BsonParser 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);
}
}
Aggregations