com.fitbur.jackson.databind.ext.PathDeserializer Maven / Gradle / Ivy
package com.fitbur.jackson.databind.ext;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.fitbur.jackson.core.JsonParser;
import com.fitbur.jackson.core.JsonToken;
import com.fitbur.jackson.databind.DeserializationContext;
import com.fitbur.jackson.databind.deser.std.StdScalarDeserializer;
public class PathDeserializer extends StdScalarDeserializer
{
private static final long serialVersionUID = 1;
public PathDeserializer() { super(Path.class); }
@Override
public Path deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonToken t= p.getCurrentToken();
if (t != null) {
if (t.isScalarValue()) {
return Paths.get(p.getValueAsString());
}
// 16-Oct-2015: should we perhaps allow JSON Arrays (of Strings) as well?
}
throw ctxt.mappingException(Path.class, t);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy