本文整理汇总了Java中net.minidev.json.JSONValue.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JSONValue.parse方法的具体用法?Java JSONValue.parse怎么用?Java JSONValue.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minidev.json.JSONValue
的用法示例。
在下文中一共展示了JSONValue.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Configuration config = configurationProvider.getFor(request.getResource().getResourceType());
Collection<String> propsWithJSONValues = config.asStrings(XK_DESERIALIZE_JSON_PROPS_CP, Mode.MERGE);
for(String propName : propsWithJSONValues) {
if(contentModel.has(propName)) {
String jsonString = contentModel.getAsString(propName);
if(JSONValue.isValidJson(jsonString)) {
Object value = JSONValue.parse(jsonString);
contentModel.set(propName, value);
}
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例2: process
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModelImpl contentModel)
throws ProcessException {
try {
Resource resource = (Resource) executionContext.get(JAHIA_RESOURCE);
Configuration configuration = configurationProvider.getFor(resource);
Collection<String> propsWithJSONValues = configuration.asStrings(XK_DESERIALIZE_JSON_PROPS_CP, Mode.MERGE);
for(String propName : propsWithJSONValues) {
if(contentModel.has(propName)) {
String jsonString = contentModel.getAsString(propName);
if(JSONValue.isValidJson(jsonString)) {
Object value = JSONValue.parse(jsonString);
contentModel.set(propName, value);
}
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例3: map
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
if (targetType.isAssignableFrom(source.getClass())) {
return (T) source;
}
try {
if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
return factory.call().getMapper(targetType).convert(source);
}
String s = configuration.jsonProvider().toJson(source);
return (T) JSONValue.parse(s, targetType);
} catch (Exception e) {
throw new MappingException(e);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:20,代码来源:JsonSmartMappingProvider.java
示例4: JafigJSON
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public JafigJSON(Object[] parameters) {
super(parameters);
if (parameters.length != 1) {
throw new InvalidParameterException("File must be provided");
}
File file;
if (parameters[0] instanceof String) {
file = new File((String) parameters[0]);
} else if (parameters[0] instanceof File) {
file = (File) parameters[0];
} else {
throw new InvalidParameterException("File must be provided as a String, or File");
}
this.file = file;
if (file.exists()) {
try {
FileInputStream inputStream = new FileInputStream(file);
this.data = (JSONObject) JSONValue.parse(inputStream);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例5: modifyAnnotationContextArray
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
/**
* Remove useless information about annotationContexts
* @param annotationContextArray annotationContextArray from ArangoDB
* @return modified array without good-for-nothing information
*/
private JSONArray modifyAnnotationContextArray(JSONArray annotationContextArray){
JSONArray modified = new JSONArray();
for (Object newJS:annotationContextArray){
//JSONObject newJS = (JSONObject) JSONValue.parse(edge);
JSONObject newAnnotationContext = (JSONObject) JSONValue.parse(newJS.toString());
newAnnotationContext.remove(new String("_id"));
newAnnotationContext.remove(new String("_key"));
newAnnotationContext.remove(new String("_rev"));
newAnnotationContext.remove(new String("_from"));
newAnnotationContext.remove(new String("_to"));
modified.add(newAnnotationContext);
}
return modified;
}
示例6: testJSONEventLayoutHasUserFieldsFromProps
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void testJSONEventLayoutHasUserFieldsFromProps() {
System.setProperty(JSONEventLayoutV1.ADDITIONAL_DATA_PROPERTY, userFieldsSingleProperty);
logger.info("Test9: JSON Event Layout Has User Fields From Props");
String message = appender.getMessages()[0];
Assert.assertTrue("Event is not valid JSON", JSONValue.isValidJsonStrict(message));
Object obj = JSONValue.parse(message);
JSONObject jsonObject = (JSONObject) obj;
Assert.assertTrue("Event does not contain field 'field1'" , jsonObject.containsKey("field1"));
Assert.assertEquals("Event does not contain value 'value1'", "propval1", jsonObject.get("field1"));
System.clearProperty(JSONEventLayoutV1.ADDITIONAL_DATA_PROPERTY);
}
示例7: testJSONEventLayoutUserFieldsMulti
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void testJSONEventLayoutUserFieldsMulti() {
JSONEventLayoutV1 layout = (JSONEventLayoutV1) appender.getLayout();
layout.setUserFields(userFieldsMulti);
logger.info("Test11: JSON Event Layout Has User Fields Multi");
String message = appender.getMessages()[0];
Assert.assertTrue("Event is not valid JSON", JSONValue.isValidJsonStrict(message));
Object obj = JSONValue.parse(message);
JSONObject jsonObject = (JSONObject) obj;
Assert.assertTrue("Event does not contain field 'field2'" , jsonObject.containsKey("field2"));
Assert.assertEquals("Event does not contain value 'value2'", "value2", jsonObject.get("field2"));
Assert.assertTrue("Event does not contain field 'field3'" , jsonObject.containsKey("field3"));
Assert.assertEquals("Event does not contain value 'value3'", "value3", jsonObject.get("field3"));
}
示例8: searchList
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
/**
* A naive "search" that lists the objects, then filters them.
* This is not an efficient search technique and should be avoided
* in favor of the solr-base search method
* @deprecated
*/
private String searchList(String query) throws Exception {
JSONObject results = new JSONObject();
String annotationsContent = this.index();
JSONArray annotations = (JSONArray) JSONValue.parse(annotationsContent);
Collection<Predicate> predicates = new ArrayList<Predicate>();
List<NameValuePair> criteria = URLEncodedUtils.parse(query, Charset.forName(DEFAULT_ENCODING));
for (NameValuePair pair: criteria) {
if (pair.getName().equals("limit") || pair.getName().equals("offset")) {
continue;
}
// otherwise add the criteria
predicates.add(new AnnotationPredicate(pair.getName(), pair.getValue()));
}
Predicate allPredicate = PredicateUtils.allPredicate(predicates);
CollectionUtils.filter(annotations, allPredicate);
results.put("total", annotations.size());
results.put("rows", annotations);
return results.toJSONString();
}
示例9: extractPartitions
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
public String[] extractPartitions(Message message) {
JSONObject jsonObject = (JSONObject) JSONValue.parse(message.getPayload());
String result[] = { defaultDate };
if (jsonObject != null) {
Object fieldValue = getJsonFieldValue(jsonObject);
if (fieldValue != null && inputPattern != null) {
try {
Date dateFormat = inputFormatter.parse(fieldValue.toString());
result[0] = mDtPrefix + outputFormatter.format(dateFormat);
} catch (Exception e) {
LOG.warn("Impossible to convert date = {} with the input pattern = {}. Using date default = {}",
fieldValue.toString(), inputPattern.toString(), result[0]);
}
}
}
return result;
}
示例10: extractTimestampMillis
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
public long extractTimestampMillis(final Message message) {
JSONObject jsonObject = (JSONObject) JSONValue.parse(message.getPayload());
Object fieldValue = jsonObject != null ? getJsonFieldValue(jsonObject) : null;
if (m_timestampRequired && fieldValue == null) {
throw new RuntimeException("Missing timestamp field for message: " + message);
}
if (fieldValue != null) {
try {
Date dateFormat = DatatypeConverter.parseDateTime(fieldValue.toString()).getTime();
return dateFormat.getTime();
} catch (IllegalArgumentException ex) {
if (m_timestampRequired){
throw new RuntimeException("Bad timestamp field for message: " + message);
}
}
}
return 0;
}
示例11: fromJson
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public static Object fromJson(String s, String className) {
try {
Class clazz = Class.forName(className);
return JSONValue.parse(s, clazz);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: setUp
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
jo = (JSONObject) JSONValue
.parse(new FileReader("src/test/resources/org/afm/apath/core/books.json"));
processor = new PathProcessor();
}
示例13: map
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Override
protected void map(Text key, Text value, Context context)
throws IOException, InterruptedException {
if (!needSetId) {
context.write(NullWritable.get(), value);
} else {
JSONObject obj = (JSONObject) JSONValue.parse(value.toString());
obj.put("id", key.toString());
context.write(NullWritable.get(), new Text(obj.toJSONString()));
}
}
示例14: readJsonFile
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public static JSONObject readJsonFile(String filePath) {
final InputStream fileStream = Utils.class.getClass().getResourceAsStream(filePath);
if (fileStream == null) {
throw new RuntimeException(new FileNotFoundException(filePath));
}
try {
return JSONValue.parse(new InputStreamReader(fileStream, "UTF-8"), JSONObject.class);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例15: testJSONEventLayoutHasKeys
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void testJSONEventLayoutHasKeys() {
logger.info("Test2: JSON Event Layout Has Keys");
String message = appender.getMessages()[0];
Object obj = JSONValue.parse(message);
JSONObject jsonObject = (JSONObject) obj;
for (String fieldName : logstashFields) {
Assert.assertTrue("Event does not contain field: " + fieldName, jsonObject.containsKey(fieldName));
}
}