本文整理汇总了Java中com.fasterxml.jackson.core.JsonStreamContext.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java JsonStreamContext.getParent方法的具体用法?Java JsonStreamContext.getParent怎么用?Java JsonStreamContext.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonStreamContext
的用法示例。
在下文中一共展示了JsonStreamContext.getParent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOnType
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
/** Get type for "on" values that are plain URIs by deducing the type from their parent. */
private String getOnType(DeserializationContext ctxt) {
// Easiest way: The parser has already constructed an annotation object with a motivation.
// This is highly dependendant on the order of keys in the JSON, i.e. if "on" is the first key in the annotation
// object, this won't work.
Object curVal = ctxt.getParser().getCurrentValue();
boolean isPaintingAnno = (curVal != null && curVal instanceof Annotation &&
((Annotation) curVal).getMotivation() != null &&
((Annotation) curVal).getMotivation().equals(Motivation.PAINTING));
if (isPaintingAnno) {
return "sc:Canvas";
}
// More reliable way: Walk up the parsing context until we hit a IIIF resource that we can deduce the type from
// Usually this shouldn't be more than two levels up
JsonStreamContext parent = ctxt.getParser().getParsingContext().getParent();
while (parent != null && (parent.getCurrentValue() == null || !(parent.getCurrentValue() instanceof Resource))) {
parent = parent.getParent();
}
if (parent != null) {
Resource parentObj = (Resource) parent.getCurrentValue();
return parentObj.getType();
}
return null;
}
示例2: getPath
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
private Path getPath(PropertyWriter writer, JsonStreamContext sc) {
LinkedList<PathElement> elements = new LinkedList<>();
if (sc != null) {
elements.add(new PathElement(writer.getName(), sc.getCurrentValue()));
sc = sc.getParent();
}
while (sc != null) {
if (sc.getCurrentName() != null && sc.getCurrentValue() != null) {
elements.addFirst(new PathElement(sc.getCurrentName(), sc.getCurrentValue()));
}
sc = sc.getParent();
}
return new Path(elements);
}
示例3: willRecursive
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
private boolean willRecursive(JsonGenerator gen, JsonStreamContext ctxt, Method method) throws IOException {
if (ctxt != null) {
JsonStreamContext ptxt = ctxt.getParent();
while(ptxt != null) {
// if(ctxt.getCurrentValue() != ptxt.getCurrentValue()) {
// ptxt = ptxt.getParent();
// }else {
// gen.writeEndObject();
// return;
// }
// if(ptxt.getCurrentValue() == null || !ctxt.getCurrentValue().getClass().equals(ptxt.getCurrentValue().getClass())) {
// ptxt = ptxt.getParent();
// }else {
// gen.writeEndObject();
// return;
// }
// String typeName = method.getGenericReturnType().getTypeName();
if(ptxt.getCurrentValue() == null || !ReflectionUtils.getInnermostType(method).equals(ptxt.getCurrentValue().getClass().getCanonicalName())) {
ptxt = ptxt.getParent();
}else {
return true;
}
}
}
return false;
}
示例4: willRecursive
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
private boolean willRecursive(JsonStreamContext ctxt, Method method) throws IOException {
if (ctxt != null) {
JsonStreamContext ptxt;
ptxt = ctxt.getParent();
while(ptxt != null) {
if(ptxt.getCurrentValue() == null
|| !ReflectionUtils.getInnermostType(method).equals(ptxt.getCurrentValue().getClass().getCanonicalName())) {
ptxt = ptxt.getParent();
}else {
return true;
}
}
}
return false;
}
示例5: deserialize
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
@Override
public Object deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
if(jobsManager == null) {
throw new IllegalStateException("This deserializer need a jobsManager instance, see 'JobParametersDeserializer.setJobsManager'");
}
final JsonStreamContext jsc = p.getParsingContext();
String paramName = null;
JsonStreamContext parent = jsc;
while(parent != null) {
paramName = parent.getCurrentName();
if(paramName != null) {
break;
}
parent = parent.getParent();
}
if(parent == null) {
throw new NullPointerException("Something wrong: we can not find our parent object, " +
"may be you use this deserializer on custom object?");
}
JobParameters.Builder r = (JobParameters.Builder) parent.getParent().getCurrentValue();
String jobType = r.getType();
JobDescription desc = jobsManager.getDescription(jobType);
JobParameterDescription param = desc.getParameters().get(paramName);
TypeFactory typeFactory = ctx.getTypeFactory();
JavaType type;
if(param == null) {
type = typeFactory.constructType(Object.class);
} else {
type = typeFactory.constructType(param.getType());
}
JsonDeserializer<Object> deser = ctx.findNonContextualValueDeserializer(type);
try {
return deser.deserialize(p, ctx);
} catch (Exception e) {
throw new RuntimeException("Can not deserialize '" + jobType + "." + paramName + "' job parameter ", e );
}
}
示例6: mapNearestDruidQuery
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
/**
* JSON tree walk to find the druid query context of the current context and apply handler to the DruidQuery,
* finds the current context if current context is a druid query.
*
* @param gen the Json Generator to retrieve the tree to walk on.
* @param mapper a function that takes an DruidQuery as an argument and return the final desired returned result.
* @param <T> Type of result from the mapper
*
* @return an Optional of the desired result T if DruidQuery is found, Optional.empty otherwise
*/
public static <T> Optional<T> mapNearestDruidQuery(JsonGenerator gen, Function<DruidQuery, T> mapper) {
JsonStreamContext context = gen.getOutputContext();
while (context != null) {
Object parent = context.getCurrentValue();
if (parent instanceof DruidQuery) {
return Optional.of(mapper.apply((DruidQuery) parent));
}
context = context.getParent();
}
return Optional.empty();
}
示例7: expand
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
/**
* Create a collection consisting of stream contexts, starting at the root
* node and ending at the given stream context
*
* @param streamContext The stream context
* @return The collection
*/
private static Collection<JsonStreamContext> expand(
JsonStreamContext streamContext)
{
Deque<JsonStreamContext> collection =
new LinkedList<JsonStreamContext>();
JsonStreamContext current = streamContext;
while (current != null)
{
collection.addFirst(current);
current = current.getParent();
}
return collection;
}
示例8: matchesSafely
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(JsonStreamContext context, Description mismatch) {
final JsonStreamContext value = context.getParent();
if (!matcher.matches(value)) {
mismatch.appendText("parent ");
matcher.describeMismatch(value, mismatch);
return false;
}
return true;
}
示例9: getPathProperties
import com.fasterxml.jackson.core.JsonStreamContext; //导入方法依赖的package包/类
/**
* only first call return FetchPath
* <p>
* and then call is bean sub-path (property)
*
* @return fetch path or null
*/
private FetchPath getPathProperties(JsonGenerator jsonGenerator) {
FetchPath fetchPath = EbeanUtils.getRequestFetchPath();
if (fetchPath != null) {
JsonStreamContext context = jsonGenerator.getOutputContext();
JsonStreamContext parent = context.getParent();
if (parent == null) {
return fetchPath;
}
StringBuilder path = new StringBuilder();
while (parent != null && !parent.inRoot()) {
if (parent != context.getParent()) {
path.insert(0, '.');
}
path.insert(0, parent.getCurrentName());
parent = parent.getParent();
}
String fp = path.toString();
PathProperties fetch = new PathProperties();
EbeanPathProps src = (EbeanPathProps) fetchPath;
String cp = fp + ".";
for (BeanPathProperties.Props prop : src.getPathProps()) {
String pp = prop.getPath();
if (pp.equals(fp)) {
addToFetchPath(fetch, null, prop);
} else if (pp.startsWith(cp)) {
addToFetchPath(fetch, pp.substring(cp.length()), prop);
}
}
return fetch;
}
return null;
}