本文整理汇总了Java中com.fasterxml.jackson.databind.util.TokenBuffer类的典型用法代码示例。如果您正苦于以下问题:Java TokenBuffer类的具体用法?Java TokenBuffer怎么用?Java TokenBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenBuffer类属于com.fasterxml.jackson.databind.util包,在下文中一共展示了TokenBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
@Override
public void writeTo(
Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream os) throws IOException {
String fields = uriInfo.getQueryParameters() == null ? null
: uriInfo.getQueryParameters().getFirst("fields");
FieldFilter fieldFilter = FieldFilter.create(fields);
if (!fieldFilter.hasFilters()) {
super.writeTo(o, type, genericType, annotations, mediaType, httpHeaders, os);
return;
}
JsonGenerator jgen = objectMapper.getFactory().createGenerator(os);
TokenBuffer tokenBuffer = new TokenBuffer(objectMapper, false);
objectMapper.writeValue(tokenBuffer, o);
JsonParser jsonParser = tokenBuffer.asParser();
fieldFilter.writeJson(jsonParser, jgen);
jgen.flush();
}
示例2: convertToJsonNode
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private static JsonNode convertToJsonNode(RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples) throws IOException{
TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
JsonOutput json = new ExtendedJsonOutput(out);
json.writeStartArray();
String[] fields = rowType.getFieldNames().toArray(new String[rowType.getFieldCount()]);
for(List<RexLiteral> row : tuples){
json.writeStartObject();
int i =0;
for(RexLiteral field : row){
json.writeFieldName(fields[i]);
writeLiteral(field, json);
i++;
}
json.writeEndObject();
}
json.writeEndArray();
json.flush();
return out.asParser().readValueAsTree();
}
示例3: getResultsNode
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private JsonNode getResultsNode(long count) {
try{
TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
JsonOutput json = new ExtendedJsonOutput(out);
json.writeStartArray();
json.writeStartObject();
json.writeFieldName("count");
json.writeBigInt(count);
json.writeEndObject();
json.writeEndArray();
json.flush();
return out.asParser().readValueAsTree();
}catch(IOException ex){
throw Throwables.propagate(ex);
}
}
示例4: convertToJsonNode
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private static JsonNode convertToJsonNode(RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples) throws IOException {
TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
JsonOutput json = new ExtendedJsonOutput(out);
json.writeStartArray();
String[] fields = rowType.getFieldNames().toArray(new String[rowType.getFieldCount()]);
for (List<RexLiteral> row : tuples) {
json.writeStartObject();
int i = 0;
for (RexLiteral field : row) {
json.writeFieldName(fields[i]);
writeLiteral(field, json);
i++;
}
json.writeEndObject();
}
json.writeEndArray();
json.flush();
return out.asParser().readValueAsTree();
}
示例5: unmarshall
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
@Override
public <T> T unmarshall(final Object marshalled, final Class<T> type) throws Exception {
checkNotNull(marshalled);
checkState(marshalled instanceof Map, "Marshalled data must be a Map; found: %s", marshalled.getClass());
// FIXME: This allows the top-level object to be created, but if any children objects of this are missing
// FIXME: ... no-arg CTOR then Jackson will fail to construct them.
// FIXME: Is there any way to configure the basic instance creation for Jackson?
Object value = instanceCreator.newInstance(type);
// performs same basic logic as ObjectMapper.convertValue(Object, Class) helper
ObjectReader reader = objectMapper.readerForUpdating(value);
TokenBuffer buff = new TokenBuffer(objectMapper, false);
objectMapper.writeValue(buff, marshalled);
reader.readValue(buff.asParser());
return type.cast(value);
}
示例6: deserializeMetadata
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
FieldMetadata deserializeMetadata(ObjectMapper mapper, String fieldName, JsonNode fieldJson) throws JsonParseException, IOException {
TokenBuffer tb = new TokenBuffer(null, false);
JsonParser jp = fieldJson.traverse(mapper);
jp.nextToken(); // Get to Start TOKEN
JsonToken token = jp.getCurrentToken();
tb.writeStringField(NAME_PROP, fieldName);
do {
jp.nextToken();
token = jp.getCurrentToken();
tb.copyCurrentStructure(jp);
} while(token != JsonToken.END_OBJECT);
jp = tb.asParser(jp);
jp.nextToken();
tb.close();
FieldMetadata diff = mapper.readValue(jp, FieldMetadata.class);
return defaultMetaProvider.mergeWithDefault(diff);
}
示例7: enrichJsonObject
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private JsonParser enrichJsonObject(ObjectMapper mapper, String fieldName, JsonNode fieldJson) throws IOException {
TokenBuffer tb = new TokenBuffer(null, false);
JsonParser jp = fieldJson.traverse(mapper);
JsonToken token = jp.nextToken(); // Get to Start TOKEN
tb.writeStringField(NAME_PROP, fieldName);
do {
jp.nextToken();
token = jp.getCurrentToken();
tb.copyCurrentStructure(jp);
} while(token != JsonToken.END_OBJECT);
jp = tb.asParser(jp);
jp.nextToken();
tb.close();
return jp;
}
示例8: convert
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected static <T> T convert(Object fromValue, TypeReference<T> toValueType, Class<?> view) {
// sanity check for null first:
if (fromValue == null)
return null;
/*
* Then use TokenBuffer, which is a JsonGenerator: (see [JACKSON-175])
*/
TokenBuffer buf = new TokenBuffer(MAPPER);
try {
MAPPER.writerWithView(view).writeValue(buf, fromValue);
// and provide as with a JsonParser for contents as well!
JsonParser jp = buf.asParser();
Object result = MAPPER.readValue(jp, toValueType);
jp.close();
return (T) result;
} catch (IOException e) { // should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
}
示例9: _deserializeTypedUsingDefaultImpl
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
protected Object _deserializeTypedUsingDefaultImpl(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, TokenBuffer paramTokenBuffer)
{
JsonDeserializer localJsonDeserializer = _findDefaultImplDeserializer(paramDeserializationContext);
if (localJsonDeserializer != null)
{
if (paramTokenBuffer != null)
{
paramTokenBuffer.writeEndObject();
JsonParser localJsonParser = paramTokenBuffer.asParser(paramJsonParser);
paramJsonParser = localJsonParser;
localJsonParser.nextToken();
}
return localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
}
Object localObject = TypeDeserializer.deserializeIfNatural(paramJsonParser, paramDeserializationContext, this._baseType);
if (localObject != null)
return localObject;
if (paramJsonParser.getCurrentToken() == JsonToken.START_ARRAY)
return super.deserializeTypedFromAny(paramJsonParser, paramDeserializationContext);
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.FIELD_NAME, "missing property '" + this._typePropertyName + "' that is to contain type id (for class " + baseTypeName() + ")");
}
示例10: _deserialize
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private final Object _deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
boolean bool = paramJsonParser.isExpectedStartArrayToken();
String str = _locateTypeId(paramJsonParser, paramDeserializationContext);
JsonDeserializer localJsonDeserializer = _findDeserializer(paramDeserializationContext, str);
if ((this._typeIdVisible) && (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT))
{
TokenBuffer localTokenBuffer = new TokenBuffer(null);
localTokenBuffer.writeStartObject();
localTokenBuffer.writeFieldName(this._typePropertyName);
localTokenBuffer.writeString(str);
JsonParserSequence localJsonParserSequence = JsonParserSequence.createFlattened(localTokenBuffer.asParser(paramJsonParser), paramJsonParser);
paramJsonParser = localJsonParserSequence;
localJsonParserSequence.nextToken();
}
Object localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
if ((bool) && (paramJsonParser.nextToken() != JsonToken.END_ARRAY))
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.END_ARRAY, "expected closing END_ARRAY after type information and deserialized value");
return localObject;
}
示例11: _deserialize
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private final Object _deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
if (paramJsonParser.getCurrentToken() != JsonToken.START_OBJECT)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.START_OBJECT, "need JSON Object to contain As.WRAPPER_OBJECT type information for class " + baseTypeName());
if (paramJsonParser.nextToken() != JsonToken.FIELD_NAME)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.FIELD_NAME, "need JSON String that contains type id (for subtype of " + baseTypeName() + ")");
String str = paramJsonParser.getText();
JsonDeserializer localJsonDeserializer = _findDeserializer(paramDeserializationContext, str);
paramJsonParser.nextToken();
if ((this._typeIdVisible) && (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT))
{
TokenBuffer localTokenBuffer = new TokenBuffer(null);
localTokenBuffer.writeStartObject();
localTokenBuffer.writeFieldName(this._typePropertyName);
localTokenBuffer.writeString(str);
JsonParserSequence localJsonParserSequence = JsonParserSequence.createFlattened(localTokenBuffer.asParser(paramJsonParser), paramJsonParser);
paramJsonParser = localJsonParserSequence;
localJsonParserSequence.nextToken();
}
Object localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
if (paramJsonParser.nextToken() != JsonToken.END_OBJECT)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.END_OBJECT, "expected closing END_OBJECT after type information and deserialized value");
return localObject;
}
示例12: handlePolymorphic
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
protected Object handlePolymorphic(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Object paramObject, TokenBuffer paramTokenBuffer)
{
JsonDeserializer localJsonDeserializer = _findSubclassDeserializer(paramDeserializationContext, paramObject, paramTokenBuffer);
if (localJsonDeserializer != null)
{
if (paramTokenBuffer != null)
{
paramTokenBuffer.writeEndObject();
JsonParser localJsonParser = paramTokenBuffer.asParser();
localJsonParser.nextToken();
paramObject = localJsonDeserializer.deserialize(localJsonParser, paramDeserializationContext, paramObject);
}
if (paramJsonParser != null)
paramObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext, paramObject);
return paramObject;
}
if (paramTokenBuffer != null)
paramObject = handleUnknownProperties(paramDeserializationContext, paramObject, paramTokenBuffer);
if (paramJsonParser != null)
paramObject = deserialize(paramJsonParser, paramDeserializationContext, paramObject);
return paramObject;
}
示例13: valueToTree
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
private JsonNode valueToTree(ObjectMapper mapper, ObjectWriter writer, Object o) {
if (o == null) {
return null;
}
TokenBuffer buf = new TokenBuffer(mapper, false);
JsonNode result;
try {
writer.writeValue(buf, o);
JsonParser jp = buf.asParser();
result = mapper.readTree(jp);
jp.close();
} catch (IOException e) { // should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
return result;
}
开发者ID:HubSpot,项目名称:jackson-jaxrs-propertyfiltering,代码行数:19,代码来源:PropertyFilteringMessageBodyWriter.java
示例14: _deserialize
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
/**
* Method that handles type information wrapper, locates actual
* subtype deserializer to use, and calls it to do actual
* deserialization.
*/
private final Object _deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
boolean hadStartArray = jp.isExpectedStartArrayToken();
String typeId = _locateTypeId(jp, ctxt);
JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId);
// Minor complication: we may need to merge type id in?
if (_typeIdVisible && jp.getCurrentToken() == JsonToken.START_OBJECT) {
// but what if there's nowhere to add it in? Error? Or skip? For now, skip.
TokenBuffer tb = new TokenBuffer(null);
tb.writeStartObject(); // recreate START_OBJECT
tb.writeFieldName(_typePropertyName);
tb.writeString(typeId);
jp = JsonParserSequence.createFlattened(tb.asParser(jp), jp);
jp.nextToken();
}
Object value = deser.deserialize(jp, ctxt);
// And then need the closing END_ARRAY
if (hadStartArray && jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"expected closing END_ARRAY after type information and deserialized value");
}
return value;
}
示例15: _deserialize
import com.fasterxml.jackson.databind.util.TokenBuffer; //导入依赖的package包/类
protected final Object _deserialize(JsonParser jp, DeserializationContext ctxt,
int index)
throws IOException, JsonProcessingException
{
TokenBuffer merged = new TokenBuffer(jp.getCodec());
merged.writeStartArray();
merged.writeString(_typeIds[index]);
JsonParser p2 = _tokens[index].asParser(jp);
p2.nextToken();
merged.copyCurrentStructure(p2);
merged.writeEndArray();
// needs to point to START_OBJECT (or whatever first token is)
p2 = merged.asParser(jp);
p2.nextToken();
return _properties[index].getProperty().deserialize(p2, ctxt);
}