本文整理汇总了Java中com.fasterxml.jackson.core.JsonParser.Feature类的典型用法代码示例。如果您正苦于以下问题:Java Feature类的具体用法?Java Feature怎么用?Java Feature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Feature类属于com.fasterxml.jackson.core.JsonParser包,在下文中一共展示了Feature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
private StructObjectInspector initialize(final ObjectInspector jsonArg, final ObjectInspector jqArg, final List<ObjectInspector> nameAndTypeArgs) throws UDFArgumentException {
this.in = Arguments.asString(jsonArg, "JSON");
try {
this.jq = JsonQuery.compile(Arguments.asConstantNonNullString(jqArg, "JQ"));
} catch (final JsonQueryException e) {
throw new UDFArgumentException("JQ is invalid: " + e.getMessage());
}
this.marshaller = ResultObjectMarshallers.create(Arguments.asConstantNonNullStrings(nameAndTypeArgs, "TYPE or NAME:TYPE"));
this.scope = new Scope();
this.mapper = new ObjectMapper(new JsonFactory().enable(Feature.ALLOW_UNQUOTED_CONTROL_CHARS));
return marshaller.objectInspector();
}
示例2: testArrayInnerComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@Test
public void testArrayInnerComma() throws Exception {
String json = "[\"a\",, \"b\"]";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.currentText());
if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertUnexpected(p, ',');
return;
}
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.currentText());
assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
}
示例3: testArrayLeadingComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@Test
public void testArrayLeadingComma() throws Exception {
String json = "[,\"a\", \"b\"]";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertUnexpected(p, ',');
return;
}
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.currentText());
assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
p.close();
}
示例4: testObjectTrailingComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@Test
public void testObjectTrailingComma() throws Exception {
String json = "{\"a\": true, \"b\": false,}";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("b", p.currentText());
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
if (features.contains(Feature.ALLOW_TRAILING_COMMA)) {
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertEnd(p);
} else {
assertUnexpected(p, '}');
}
p.close();
}
示例5: testArrayInnerComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testArrayInnerComma() throws Exception {
String json = "[\"a\",, \"b\"]";
JsonParser p = createParser(factory, mode, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.getText());
if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertUnexpected(p, ',');
return;
}
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.getText());
assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
}
示例6: testArrayLeadingComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testArrayLeadingComma() throws Exception {
String json = "[,\"a\", \"b\"]";
JsonParser p = createParser(factory, mode, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertUnexpected(p, ',');
return;
}
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.getText());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.getText());
assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
p.close();
}
示例7: testObjectTrailingComma
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@Test
public void testObjectTrailingComma() throws Exception {
String json = "{\"a\": true, \"b\": false,}";
JsonParser p = createParser(factory, mode, json);
assertEquals(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("a", p.getText());
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("b", p.getText());
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
if (features.contains(Feature.ALLOW_TRAILING_COMMA)) {
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertEnd(p);
} else {
assertUnexpected(p, '}');
}
p.close();
}
示例8: LogicalPlanPersistence
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
public LogicalPlanPersistence(SabotConfig conf, ScanResult scanResult) {
mapper = new ObjectMapper();
SimpleModule deserModule = new SimpleModule("LogicalExpressionDeserializationModule")
.addDeserializer(LogicalExpression.class, new LogicalExpression.De(conf))
.addDeserializer(SchemaPath.class, new SchemaPath.De());
mapper.registerModule(new AfterburnerModule());
mapper.registerModule(deserModule);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_COMMENTS, true);
registerSubtypes(LogicalOperatorBase.getSubTypes(scanResult));
registerSubtypes(StoragePluginConfigBase.getSubTypes(scanResult));
registerSubtypes(FormatPluginConfigBase.getSubTypes(scanResult));
}
示例9: readServiceInformation
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
/**
* Reads service information.
*
* @param folder folder
* @param si service info obtained through {@link listContent}
* @return service response
* @throws URISyntaxException if invalid URL
* @throws IOException if accessing token fails
*/
public ServerResponse readServiceInformation(String folder, ServiceInfo si) throws URISyntaxException, IOException {
String url = rootUrl.toURI().resolve("rest/services/").resolve(StringUtils.stripToEmpty(folder)).resolve(si.name + "/" + si.type).toASCIIString();
HttpGet get = new HttpGet(url + String.format("?f=%s", "json"));
try (CloseableHttpResponse httpResponse = httpClient.execute(get); InputStream contentStream = httpResponse.getEntity().getContent();) {
if (httpResponse.getStatusLine().getStatusCode()>=400) {
throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase());
}
String responseContent = IOUtils.toString(contentStream, "UTF-8");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ServerResponse response = mapper.readValue(responseContent, ServerResponse.class);
response.url = url;
response.json = responseContent;
return response;
}
}
示例10: JacksonObjectMapperConfig
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
public JacksonObjectMapperConfig() {
super();
this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
//this.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); 不增加,避免key值为null,而避免节点消失
this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
//this.setSerializationInclusion(Include.NON_EMPTY); //对象转字符串时,只转化非空字段 zjs 需要占位
//SimpleModule module = new SimpleModule();
SimpleModule module = new SimpleModule("HTML XSS Serializer",
new Version(1, 0, 0, "FINAL", "com.simbest", "ep-jsonmodule"));
module.addSerializer(new JsonHtmlXssSerializer(String.class));
module.addDeserializer(Date.class, new CustomJsonDateDeseralizer());
// Add more here ...
registerModule(module);
}
示例11: setStatusMessage
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
public void setStatusMessage(String statusMessage) {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES,true);
mapper.configure(Feature.ALLOW_SINGLE_QUOTES,true);
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
JsonNode node = mapper.readValue(statusMessage.getBytes(), JsonNode.class);
this.statusMessage = node.get("statusMessage").asText();
this.additionalInfo = node.get("additionalInfo");
this.step = node.get("step").asText();
} catch (Exception e) {
System.out.println(statusMessage);
// e.printStackTrace();
}
}
示例12: LogicalPlanPersistence
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
public LogicalPlanPersistence(DrillConfig conf, ScanResult scanResult) {
mapper = new ObjectMapper();
SimpleModule deserModule = new SimpleModule("LogicalExpressionDeserializationModule")
.addDeserializer(LogicalExpression.class, new LogicalExpression.De(conf))
.addDeserializer(SchemaPath.class, new SchemaPath.De());
mapper.registerModule(deserModule);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_COMMENTS, true);
registerSubtypes(LogicalOperatorBase.getSubTypes(scanResult));
registerSubtypes(StoragePluginConfigBase.getSubTypes(scanResult));
registerSubtypes(FormatPluginConfigBase.getSubTypes(scanResult));
}
示例13: fromJSON
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
/**
* Convenience static method that reads a JSON string from the given stream and converts the JSON
* string to a particular message object. The input stream will remain open so the caller can
* stream any extra data that might appear after it.
*
* Because of the way the JSON parser works, some extra data might have been read from the stream
* that wasn't part of the JSON message but was part of the extra data that came with it. Because of this,
* the caller should no longer use the given stream but instead read the extra data via the returned
* object (see {@link BasicMessageWithExtraData#getBinaryData()}) since it will handle this condition
* properly.
*
* @param in input stream that has a JSON string at the head.
* @param clazz the class whose instance is represented by the JSON string
*
* @return a POJO that contains a message object that was represented by the JSON string found
* in the stream. This returned POJO will also contain a {@link BinaryData} object that you
* can use to stream any additional data that came in the given input stream.
*/
public static <T extends BasicMessage> BasicMessageWithExtraData<T> fromJSON(InputStream in, Class<T> clazz) {
final T obj;
final byte[] remainder;
try (JsonParser parser = new JsonFactory().configure(Feature.AUTO_CLOSE_SOURCE, false).createParser(in)) {
Method buildObjectMapperForDeserializationMethod = findBuildObjectMapperForDeserializationMethod(clazz);
final ObjectMapper mapper = (ObjectMapper) buildObjectMapperForDeserializationMethod.invoke(null);
if (FailOnUnknownProperties.class.isAssignableFrom(clazz)) {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
}
obj = mapper.readValue(parser, clazz);
final ByteArrayOutputStream remainderStream = new ByteArrayOutputStream();
final int released = parser.releaseBuffered(remainderStream);
remainder = (released > 0) ? remainderStream.toByteArray() : new byte[0];
} catch (Exception e) {
throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e);
}
return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
}
示例14: jsonObjectMapper
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
@Bean
public ObjectMapper jsonObjectMapper() {
final ObjectMapper jsonMapper = new ObjectMapper();
jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion());
module.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType,
final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) {
return new FieldsMapMixInLikeSerializer();
} else {
return super.modifyMapSerializer(config, valueType, beanDesc, serializer);
}
}
});
jsonMapper.registerModule(module);
return jsonMapper;
}
示例15: _skipComment
import com.fasterxml.jackson.core.JsonParser.Feature; //导入依赖的package包/类
private void _skipComment()
{
if (!isEnabled(JsonParser.Feature.ALLOW_COMMENTS))
_reportUnexpectedChar(47, "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
if ((this._inputPtr >= this._inputEnd) && (!loadMore()))
_reportInvalidEOF(" in a comment");
byte[] arrayOfByte = this._inputBuffer;
int i = this._inputPtr;
this._inputPtr = (i + 1);
int j = 0xFF & arrayOfByte[i];
if (j == 47)
{
_skipCppComment();
return;
}
if (j == 42)
{
_skipCComment();
return;
}
_reportUnexpectedChar(j, "was expecting either '*' or '/' for a comment");
}