本文整理汇总了Java中com.fasterxml.jackson.core.JsonStreamContext类的典型用法代码示例。如果您正苦于以下问题:Java JsonStreamContext类的具体用法?Java JsonStreamContext怎么用?Java JsonStreamContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonStreamContext类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonStreamContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJsonPath
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
static String toJsonPath(JsonStreamContext context) {
StringBuilder builder = new StringBuilder();
for (JsonStreamContext c = context; c != null; c = c.getParent()) {
if (c.inArray()) {
builder.insert(0, "[" + c.getCurrentIndex() + "]");
} else if (c.inObject()) {
@Nullable String name = c.getCurrentName();
if (name == null || name.isEmpty()) {
builder.insert(0, "[]");
} else if (isAsciiIdentifierPath(name)) {
builder.insert(0, "." + name);
} else {
builder.insert(0, "['" + name + "']");
}
} else if (c.inRoot()) {
builder.insert(0, "$");
}
}
return builder.toString();
}
示例2: 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;
}
示例3: close
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
public void close() throws IOException {
if (generator.isClosed()) {
return;
}
JsonStreamContext context = generator.getOutputContext();
if ((context != null) && (context.inRoot() == false)) {
throw new IOException("Unclosed object or array found");
}
if (writeLineFeedAtEnd) {
flush();
// Bypass generator to always write the line feed
getLowLevelGenerator().writeRaw(LF);
}
generator.close();
}
示例4: 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);
}
示例5: close
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
private void close() throws IOException {
if ( !shallowObjects.isEmpty() ) {
for (String o : shallowObjects) {
jg.writeFieldName(o);
jg.writeBoolean(true);
}
}
while (jg.getOutputContext().getParent() != null) {
JsonStreamContext oc = jg.getOutputContext();
if (oc.inObject()) {
jg.writeEndObject();
} else if (oc.inArray()) {
jg.writeEndArray();
}
}
jg.flush();
if( options.callback()!=null ) {
output.write(")".getBytes(StandardCharsets.UTF_8));
}
jg.close();
}
示例6: matchesSafely
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
protected boolean matchesSafely(JsonStreamContext context, Description mismatch) {
if (context.inArray()) {
mismatch.appendText("was of type ARRAY");
return false;
}
if (context.inRoot()) {
mismatch.appendText("was of type ROOT");
return false;
}
if (!context.inObject()) {
mismatch.appendText("was not of type OBJECT");
return false;
}
return true;
}
示例7: matchesSafely
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
protected boolean matchesSafely(JsonStreamContext context, Description mismatch) {
if (context.inRoot()) {
mismatch.appendText("was of type ROOT");
return false;
}
if (context.inObject()) {
mismatch.appendText("was of type OBJECT");
return false;
}
if (!context.inArray()) {
mismatch.appendText("was not of type ARRAY");
return false;
}
return true;
}
示例8: matchesSafely
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
protected boolean matchesSafely(JsonStreamContext context, Description mismatch) {
if (context.inObject()) {
mismatch.appendText("was of type OBJECT");
return false;
}
if (context.inArray()) {
mismatch.appendText("was of type ARRAY");
return false;
}
if (!context.inRoot()) {
mismatch.appendText("was not of type ROOT");
return false;
}
return true;
}
示例9: writeFieldsEnd
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
public void writeFieldsEnd(FSTClazzInfo serializationInfo) {
try {
JsonStreamContext outputContext = gen.getOutputContext();
if ( outputContext.inObject() ) {
gen.writeEndObject();
} else {
gen.writeEndArray();
}
if ( outputContext.inObject() )
gen.writeEndObject();
} catch (IOException e) {
FSTUtil.<RuntimeException>rethrow(e);
try {
gen.flush();
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println( new String(out.buf,0,out.pos) );
}
}
示例10: getContainingField
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
private static String getContainingField(JsonGenerator gen) {
JsonStreamContext ctx = gen.getOutputContext();
if (ctx.inArray()) {
return ctx.getParent().getCurrentName();
} else {
return ctx.getCurrentName();
}
}
示例11: getContainingField
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
private static String getContainingField(JsonParser parser) {
final JsonStreamContext ctx = parser.getParsingContext();
if (ctx.inArray()) {
return ctx.getParent().getCurrentName();
} else {
return ctx.getCurrentName();
}
}
示例12: inRoot
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
protected boolean inRoot() {
if (isFiltered()) {
JsonStreamContext context = filter.getFilterContext();
return ((context != null) && (context.inRoot() && context.getCurrentName() == null));
}
return false;
}
示例13: serialize
import com.fasterxml.jackson.core.JsonStreamContext; //导入依赖的package包/类
@Override
public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException {
JsonStreamContext context = gen.getOutputContext();
gen.setCurrentValue(value); // must set manually, or else the result of context.getCurrentValue() will be null。this method will call context.setCurrentValue(value);
gen.writeStartObject(); // writeStartObject(value) will call setCurrentValue(value) well
Class<?> entityClass = value.getClass();
Method[] methods = entityClass.getMethods(); // include method inherited from super classes
for(Method method : methods) {
// check whether serialization will be recursive
if (willRecursive(gen, context, method)) {
gen.writeEndObject();
return;
}
// method annotated with @Field
Field fieldAnnotation = method.getAnnotation(Field.class);
if(fieldAnnotation != null) {
serializeField(value, gen, entityClass, method, fieldAnnotation);
}else {
MultiFields multiFields = method.getAnnotation(MultiFields.class);
if(multiFields != null) {
Field mainFieldAnnotation = multiFields.mainField();
serializeField(value, gen, entityClass, method, mainFieldAnnotation);
}
}
}
// gen.writeObjectField("extra_field", "whatever_value");
gen.writeEndObject();
}
示例14: 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;
}
示例15: 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;
}