本文整理汇总了Java中com.jayway.jsonpath.InvalidJsonException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidJsonException类的具体用法?Java InvalidJsonException怎么用?Java InvalidJsonException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidJsonException类属于com.jayway.jsonpath包,在下文中一共展示了InvalidJsonException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException
{
try
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int size;
while( (size=jsonStream.read(buffer))>0 )
{
stream.write(buffer, 0, size);
}
return parse(new JettisonTokener(new String(stream.toByteArray(), charset)));
}
catch( IOException ioe )
{
throw new InvalidJsonException(ioe);
}
}
示例2: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse (String jsonString) throws InvalidJsonException
{
try
{
Reader r = new StringReader (jsonString);
TextJsonParser p = new TextJsonParser (r);
p.next (); // read the very first token to get initiated.
JsonValue v = p.getValue ();
p.close ();
return v;
}
catch (JsonException ex)
{
throw new InvalidJsonException (ex);
}
}
示例3: measureWithGenerics
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
/**
* The generic version of measure.
* The class to pass should define the individual field's representations, so
* it is bound to the schema the record in. The class should be the extension
* of XmlFieldInstance
*
* @param <T>
* A class defining the internal representation of a field. It should be
* an extension of XmlFieldInstance
* @param jsonRecord
* The JSON record
* @return
* The result of measurements as a CSV string
* @throws InvalidJsonException
*/
protected <T extends XmlFieldInstance> String measureWithGenerics(String jsonRecord)
throws InvalidJsonException {
changed();
// JsonPathCache<T> cache = new JsonPathCache<>(jsonRecord);
cache = new JsonPathCache<>(jsonRecord);
List<String> items = new ArrayList<>();
for (Calculator calculator : getCalculators()) {
calculator.measure(cache);
items.add(calculator.getCsv(false, compressionLevel));
}
return StringUtils.join(items, ",");
}
示例4: handleInputNotReadableException
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@ExceptionHandler({HttpMessageNotReadableException.class, InvalidJsonException.class, InvalidFormatException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ResponseError handleInputNotReadableException(Exception exception) {
final Throwable cause = exception.getCause() == null ? exception : exception.getCause();
if (cause instanceof UnrecognizedPropertyException) {
return constructError("error.invalid_json_key", ((UnrecognizedPropertyException) cause).getPropertyName());
} else if (cause instanceof InvalidTypeIdException
|| (cause instanceof JsonMappingException && cause.getMessage()
.contains("missing property 'type'"))) {
return constructError("error.invalid_type_with_set_prompt");
} else if (cause instanceof InvalidFormatException) {
for (InvalidFormatException.Reference reference : ((InvalidFormatException) cause)
.getPath()) {
if ("operations".equals(reference.getFieldName())) {
return constructError("error.permission.invalid_operation");
}
}
}
return badRequestResponse();
}
示例5: testAssigningRawTextWhichOtherwiseConfusesKarate
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Test
public void testAssigningRawTextWhichOtherwiseConfusesKarate() {
ScriptContext ctx = getContext();
try {
Script.assign("foo", "{ not json }", ctx);
fail("we expected this to fail");
} catch (InvalidJsonException e) {
logger.debug("expected {}", e.getMessage());
}
Script.assignText("foo", "{ not json }", ctx, true);
assertTrue(Script.matchNamed(MatchType.EQUALS, "foo", null, "'{ not json }'", ctx).pass);
}
示例6: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(String json) throws InvalidJsonException {
try {
return new JSONTokener(json).nextValue();
} catch (JSONException e) {
throw new InvalidJsonException(e);
}
}
示例7: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(String json) throws InvalidJsonException {
try {
return objectMapper.readTree(json);
} catch (IOException e) {
throw new InvalidJsonException(e, json);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:9,代码来源:JacksonJsonNodeJsonProvider.java
示例8: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(final InputStream jsonStream, final String charset) throws InvalidJsonException {
try {
return PARSER.parse(new InputStreamReader(jsonStream, charset));
} catch (UnsupportedEncodingException e) {
throw new JsonPathException(e);
}
}
示例9: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
public Object parse(String json) {
try {
return createParser().parse(json, mapper);
} catch (ParseException e) {
throw new InvalidJsonException(e);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:8,代码来源:JsonSmartJsonProvider.java
示例10: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(String json) throws InvalidJsonException {
try {
return objectReader.readValue(json);
} catch (IOException e) {
throw new InvalidJsonException(e, json);
}
}
示例11: toJson
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public String toJson(Object obj) {
StringWriter writer = new StringWriter();
try {
JsonGenerator generator = objectMapper.getFactory().createGenerator(writer);
objectMapper.writeValue(generator, obj);
writer.flush();
writer.close();
generator.close();
return writer.getBuffer().toString();
} catch (IOException e) {
throw new InvalidJsonException();
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:15,代码来源:JacksonJsonProvider.java
示例12: measure
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public void measure(JsonPathCache cache)
throws InvalidJsonException {
resultMap = new FieldCounter<>();
List<XmlFieldInstance> instances = cache.get(getIdPath());
if (instances == null || instances.size() == 0) {
logger.severe("No record ID in " + cache.getJsonString());
resultMap.put(FIELD_NAME, "");
return;
}
String recordId = instances.get(0).getValue().trim();
cache.setRecordId(recordId);
resultMap.put(FIELD_NAME, recordId);
if (schema != null) {
String path;
for (String fieldName : schema.getExtractableFields().keySet()) {
if (!fieldName.equals(FIELD_NAME)) {
path = schema.getExtractableFields().get(fieldName);
List<XmlFieldInstance> values = (List<XmlFieldInstance>) cache.get(path);
String value = null;
if (values == null || values.isEmpty() || values.size() == 0 || values.get(0) == null || values.get(0).getValue() == null) {
// logger.warning("Null value in field: " + fieldName + " (" + path + ")");
value = null;
} else {
value = values.get(0).getValue();
}
resultMap.put(fieldName, value);
}
}
}
}
示例13: measure
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public void measure(JsonPathCache cache)
throws InvalidJsonException {
rawLanguageMap = new LinkedHashMap<>();
if (schema.getCollectionPaths().isEmpty()) {
measureFlatSchema(cache);
} else {
measureHierarchicalSchema(cache);
}
saturationMap = calculateScore(rawLanguageMap);
}
示例14: testInvalidRecord
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Test
public void testInvalidRecord() throws URISyntaxException, IOException {
thrown.expect(InvalidJsonException.class);
thrown.expectMessage("Unexpected character (:) at position 28");
cache = new JsonPathCache(FileUtils.readFirstLine("general/invalid.json"));
calculator.measure(cache);
fail("Should throw an exception if the JSON string is invalid.");
}
示例15: parse
import com.jayway.jsonpath.InvalidJsonException; //导入依赖的package包/类
@Override
public Object parse(String json) throws InvalidJsonException {
try {
return mapper.readValue(json, Object.class);
} catch (IOException e) {
throw new InvalidJsonException(e.getMessage(), e);
}
}