Java Code Examples for org.codehaus.jackson.JsonNode

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-xbmcremote, under directory /src/org/xbmc/jsonrpc/client/.

Source file: MusicClient.java

  23 
vote

private ArrayList<Album> getAlbums(INotifiableManager manager,ObjNode obj){
  final ArrayList<Album> albums=new ArrayList<Album>();
  final JsonNode result=mConnection.getJson(manager,"MusicLibrary.GetAlbums",obj);
  final JsonNode jsonAlbums=result.get("albums");
  for (Iterator<JsonNode> i=jsonAlbums.getElements(); i.hasNext(); ) {
    JsonNode jsonAlbum=(JsonNode)i.next();
    albums.add(new Album(getInt(jsonAlbum,"albumid"),getString(jsonAlbum,"label"),getString(jsonAlbum,"artist"),getInt(jsonAlbum,"year"),getString(jsonAlbum,"thumbnail","NONE")));
  }
  return albums;
}
 

Example 2

From project atlas, under directory /src/test/java/com/ning/atlas/.

Source file: TestJRubyTemplateParser.java

  23 
vote

@Test public void testMyAttributesPopulated() throws Exception {
  JRubyTemplateParser p=new JRubyTemplateParser();
  Template t=p.parseSystem(new File("src/test/ruby/ex1/system-template.rb")).get(0);
  List<Template> leaves=Trees.leaves(t);
  Template appc=Iterables.find(leaves,beanPropertyEquals("type","appcore"));
  My my=appc.getMy();
  JsonNode json=factory.createJsonParser(my.toJson()).readValueAsTree();
  assertThat(json.get("waffle").getIntValue(),equalTo(7));
  JsonNode r=json.get("xn.raspberry");
  assertThat(r.get(0).getIntValue(),equalTo(1));
  assertThat(r.get(1).getIntValue(),equalTo(2));
  assertThat(r.get(2).getIntValue(),equalTo(3));
}
 

Example 3

From project avro, under directory /lang/java/avro/src/main/java/org/apache/avro/data/.

Source file: Json.java

  23 
vote

@Override public JsonNode read(JsonNode reuse,Decoder in) throws IOException {
  if (written == null)   return Json.read(in);
  if (resolver == null)   resolver=DecoderFactory.get().resolvingDecoder(written,SCHEMA,null);
  resolver.configure(in);
  JsonNode result=Json.read(resolver);
  resolver.drain();
  return result;
}
 

Example 4

From project activejdbc, under directory /activejdbc/src/test/java/org/javalite/activejdbc/.

Source file: ToJsonSpec.java

  22 
vote

@Test public void shouldEscapeDoubleQuote() throws IOException {
  Page p=new Page();
  p.set("description","bad \" description");
  JsonNode node=mapper.readTree(p.toJson(true));
  a(node.get("description").toString()).shouldBeEqual("\"bad \\\" description\"");
  p=new Page();
  p.set("description",null);
  p.toJson(true);
}
 

Example 5

From project agorava-facebook, under directory /agorava-facebook-cdi/src/main/java/org/agorava/facebook/impl/.

Source file: FeedServiceImpl.java

  22 
vote

@Override public List<Post> searchPublicFeed(String query,int offset,int limit){
  Map<String,Object> params=newHashMap();
  params.put("q",query);
  params.put("type","post");
  params.put("offset",String.valueOf(offset));
  params.put("limit",String.valueOf(limit));
  String uri=buildUri("https://graph.facebook.com/search",params);
  JsonNode responseNode=getService().get(uri,JsonNode.class);
  return deserializeList(responseNode,null,Post.class);
}
 

Example 6

From project agorava-linkedin, under directory /agorava-linkedin-cdi/src/main/java/org/agorava/linkedin/jackson/.

Source file: CompanyMixin.java

  22 
vote

@Override public List<CompanyLocation> deserialize(JsonParser jp,DeserializationContext ctxt) throws IOException, JsonProcessingException {
  ObjectMapper mapper=new ObjectMapper();
  mapper.setDeserializationConfig(ctxt.getConfig());
  jp.setCodec(mapper);
  if (jp.hasCurrentToken()) {
    JsonNode dataNode=jp.readValueAsTree().get("values");
    if (dataNode != null) {
      return mapper.readValue(dataNode,new TypeReference<List<CompanyLocation>>(){
      }
);
    }
  }
  return null;
}
 

Example 7

From project agorava-twitter, under directory /agorava-twitter-cdi/src/main/java/org/agorava/twitter/jackson/.

Source file: PlacesList.java

  22 
vote

@SuppressWarnings("unchecked") @Override public List<Place> deserialize(JsonParser jp,DeserializationContext ctxt) throws IOException, JsonProcessingException {
  ObjectMapper mapper=new ObjectMapper();
  mapper.setDeserializationConfig(ctxt.getConfig());
  jp.setCodec(mapper);
  JsonNode dataNode=jp.readValueAsTree().get("places");
  return (List<Place>)mapper.readValue(dataNode,new TypeReference<List<Place>>(){
  }
);
}
 

Example 8

From project ALP, under directory /workspace/alp-utils/src/main/java/com/lohika/alp/utils/json/validator/.

Source file: ALPJSONValidator.java

  22 
vote

/** 
 * Main function used for validations.
 * @param pathToJSON - where to find file with json to validate
 * @return true if schema valid and false if wrong
 * @throws IOException Signals that an I/O exception has occurred.
 */
public boolean ValidateJSON(String pathToJSON) throws IOException {
  JSONStack.clear();
  ErrorsStack.clear();
  first_try=true;
  Reader in=new InputStreamReader(new FileInputStream(pathToJSON),"UTF-8");
  JsonNode rootObj=JSONMapper.readTree(in);
  LinkedList<String> schemaStack=new LinkedList<String>();
  schemaStack.add(schemaName);
  return validateObject(rootObj,"JSON",schemaStack);
}
 

Example 9

From project com.cedarsoft.serialization, under directory /test-utils/src/main/java/com/cedarsoft/serialization/test/utils/.

Source file: AbstractJsonSerializerTest2.java

  22 
vote

@Nonnull public static String addTypeInformation(@Nonnull String type,@Nonnull Version version,@Nonnull byte[] xmlBytes) throws Exception {
  JsonNode tree=new ObjectMapper().readTree(new String(xmlBytes));
  Map<String,JsonNode> newProps=new LinkedHashMap<String,JsonNode>();
  newProps.put("@type",new TextNode(type));
  newProps.put("@version",new TextNode(version.format()));
  Iterator<Map.Entry<String,JsonNode>> nodeIterator=((ObjectNode)tree).getFields();
  while (nodeIterator.hasNext()) {
    Map.Entry<String,JsonNode> jsonNode=nodeIterator.next();
    newProps.put(jsonNode.getKey(),jsonNode.getValue());
  }
  ((ObjectNode)tree).removeAll();
  ((ObjectNode)tree).putAll(newProps);
  return tree.toString();
}
 

Example 10

From project curator, under directory /curator-x-discovery-server/src/main/java/com/netflix/curator/x/discovery/server/entity/.

Source file: JsonServiceInstanceMarshaller.java

  22 
vote

@Override public ServiceInstance<T> readFrom(Class<ServiceInstance<T>> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,InputStream entityStream) throws IOException, WebApplicationException {
  try {
    ObjectMapper mapper=new ObjectMapper();
    JsonNode node=mapper.reader().readTree(entityStream);
    return readInstance(node,context);
  }
 catch (  Exception e) {
    throw new WebApplicationException(e);
  }
}
 

Example 11

From project droolsjbpm-integration, under directory /drools-camel/src/test/java/org/drools/camel/component/.

Source file: JSonBatchExecutionTest.java

  22 
vote

public void assertXMLEqual(String expectedXml,String resultXml){
  try {
    ObjectMapper mapper=new ObjectMapper();
    JsonNode expectedTree=mapper.readTree(expectedXml);
    JsonNode resultTree=mapper.readTree(resultXml);
    assertEquals("Expected:" + expectedXml + "\nwas:"+ resultXml,expectedTree,resultTree);
  }
 catch (  Exception e) {
    throw new RuntimeException("XML Assertion failure",e);
  }
}
 

Example 12

From project emf4sw, under directory /bundles/com.emf4sw.rdf.json/src/com/emf4sw/rdf/resource/impl/.

Source file: RDFJSONResourceImpl.java

  22 
vote

@Override protected void doSave(OutputStream outputStream,Map<?,?> options) throws IOException {
  if (!getContents().isEmpty()) {
    if (getContents().get(0) instanceof RDFGraph) {
      ObjectMapper mapper=new ObjectMapper();
      mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT,true);
      JsonNode root=RDFGraph2Json.createJsonTree((DocumentGraph)getContents().get(0));
      mapper.writeValue(outputStream,root);
    }
  }
}
 

Example 13

From project fastjson, under directory /src/test/java/com/alibaba/json/test/.

Source file: Bug_0_Test.java

  22 
vote

private void f_jackson() throws Exception {
  long startNano=System.nanoTime();
  for (int i=0; i < COUNT; ++i) {
    ObjectMapper mapper=new ObjectMapper();
    ArrayNode node=(ArrayNode)mapper.readTree(text);
    JsonNode head=node.get(0);
    JsonNode body=node.get(1);
  }
  long nano=System.nanoTime() - startNano;
  System.out.println(NumberFormat.getInstance().format(nano));
}
 

Example 14

From project GNDMS, under directory /kit/src/de/zib/gndms/kit/config/.

Source file: TreeConfig.java

  22 
vote

@Override public @NotNull ConfigProvider getDynArrayOption(@NotNull String name) throws ParseException, MandatoryOptionMissingException {
  final Object[] path=keyAsPath(name);
  JsonNode ptr=tree;
  for (  Object cursor : path)   ptr=step(ptr,cursor);
  return new TreeConfig(ptr);
}
 

Example 15

From project gnip4j, under directory /core/src/main/java/com/zaubersoftware/gnip4j/api/model/.

Source file: GeoDeserializer.java

  22 
vote

/** 
 * @see org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson.JsonParser,org.codehaus.jackson.map.DeserializationContext) 
 */
@Override public Geo deserialize(JsonParser jp,DeserializationContext ctxt) throws IOException, JsonProcessingException {
  JsonNode tree=jp.readValueAsTree();
  JsonNode coordinates=tree.findValue("coordinates");
  JsonNode type=tree.findValue("type");
  Geo geo=new Geo();
  geo.setType(type.getTextValue());
  if (Geometries.valueOf(type.getTextValue()) == Geometries.Polygon) {
    geo.setCoordinates(this.createPolygon(coordinates));
  }
 else {
    geo.setCoordinates(this.createPoint(coordinates));
  }
  return geo;
}
 

Example 16

From project greenhouse, under directory /src/main/java/com/springsource/greenhouse/signup/.

Source file: SignupFormDeserializers.java

  22 
vote

@Override public List<Integer> deserialize(JsonParser jp,DeserializationContext ctxt) throws IOException, JsonProcessingException {
  JsonNode tree=jp.readValueAsTree();
  List<Integer> fields=new ArrayList<Integer>();
  fields.add(tree.get("month").getIntValue());
  fields.add(tree.get("day").getIntValue());
  fields.add(tree.get("year").getIntValue());
  return fields;
}
 

Example 17

From project inproctester, under directory /inproctester-jersey-tests/src/test/java/com/thoughtworks/inproctester/jersey/tests/.

Source file: InProcessJerseyTest.java

  22 
vote

@Test public void shouldAddResource() throws Exception {
  WebResource webResource=resource();
  JsonNode testResource=objectMapper.readValue("{\"name\":\"test\"}",JsonNode.class);
  ClientResponse createResponse=webResource.path("/").type(MediaType.APPLICATION_JSON).entity(testResource).post(ClientResponse.class);
  Assert.assertEquals(201,createResponse.getStatus());
  Assert.assertEquals(testResource,createResponse.getEntity(JsonNode.class));
  JsonNode testResourceFromServer=webResource.uri(createResponse.getLocation()).accept(MediaType.APPLICATION_JSON).get(JsonNode.class);
  Assert.assertEquals(testResource,testResourceFromServer);
}
 

Example 18

From project json-collection, under directory /src/main/java/net/hamnaberg/json/parser/.

Source file: JsonCollectionParser.java

  22 
vote

private ErrorMessage parseError(JsonNode collectionNode){
  JsonNode errorNode=collectionNode.get("error");
  if (errorNode != null) {
    String title=getStringValue(errorNode.get("title"));
    String code=getStringValue(errorNode.get("code"));
    String message=getStringValue(errorNode.get("message"));
    if (isEmpty(title) && isEmpty(code) && isEmpty(message)) {
      return ErrorMessage.EMPTY;
    }
    return new ErrorMessage(title,code,message);
  }
  return null;
}
 

Example 19

From project JsonPath_1, under directory /src/main/java/com/nebhale/jsonpath/internal/component/.

Source file: AbstractChainedPathComponent.java

  22 
vote

@Override public final JsonNode get(JsonNode jsonNode){
  JsonNode selected=select(jsonNode);
  if ((selected != null) && (this.delegate != null)) {
    return this.delegate.get(selected);
  }
  return selected;
}
 

Example 20

From project Lily, under directory /apps/import/src/main/java/org/lilyproject/tools/import_/json/.

Source file: NamespacesConverter.java

  22 
vote

public static Namespaces fromContextJson(ObjectNode contextNode) throws JsonFormatException {
  Namespaces namespaces;
  JsonNode nsNode=contextNode.get("namespaces");
  if (nsNode == null) {
    namespaces=new Namespaces();
  }
 else   if (!nsNode.isObject()) {
    throw new JsonFormatException("The value of the namespaces property should be an object.");
  }
 else {
    namespaces=NamespacesConverter.fromJson((ObjectNode)nsNode);
  }
  return namespaces;
}
 

Example 21

From project Arecibo, under directory /alert-client-support/src/main/java/com/ning/arecibo/alert/client/.

Source file: AlertStatusJSONConverter.java

  21 
vote

public static List<AlertStatus> serializeJSONToStatusList(InputStream JSONStream) throws IOException {
  JsonParser parser=new MappingJsonFactory().createJsonParser(JSONStream);
  parser.enable(JsonParser.Feature.ALLOW_COMMENTS);
  parser.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
  parser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
  JsonNode rootNode=parser.readValueAsTree();
  JsonNode currentAlerts=rootNode.path(CURRENT_ALERTS);
  if (currentAlerts.size() == 0) {
    return null;
  }
  Iterator<JsonNode> alertNodes=currentAlerts.getElements();
  ArrayList<AlertStatus> retList=new ArrayList<AlertStatus>();
  while (alertNodes.hasNext()) {
    JsonNode alertNode=alertNodes.next();
    Map<String,String> attributes=new HashMap<String,String>();
    Iterator<String> fieldNames=alertNode.getFieldNames();
    while (fieldNames.hasNext()) {
      String fieldName=fieldNames.next();
      JsonNode valueNode=alertNode.get(fieldName);
      String value=valueNode.getTextValue();
      attributes.put(fieldName,value);
    }
    String alertId=attributes.remove(ALERT_ID);
    String alertTypeString=attributes.remove(ALERT_TYPE);
    String eventType=attributes.remove(EVENT_TYPE);
    String attributeType=attributes.remove(ATTRIBUTE_TYPE);
    String activationStatusString=attributes.remove(ACTIVATION_STATUS);
    AlertType alertType=null;
    if (alertTypeString != null)     alertType=AlertType.valueOf(alertTypeString);
    AlertActivationStatus activationStatus=null;
    if (activationStatusString != null)     activationStatus=AlertActivationStatus.valueOf(activationStatusString);
    AlertStatus alertStatus=new AlertStatus(alertId,alertType,activationStatus,eventType,attributeType);
    alertStatus.setAuxAttributeMap(attributes);
    retList.add(alertStatus);
  }
  return retList;
}
 

Example 22

From project beanstalker, under directory /simpledb-maven-plugin/src/main/java/br/com/ingenieux/mojo/simpledb/cmd/.

Source file: PutAttributesCommand.java

  21 
vote

private Collection<ReplaceableAttribute> getAttributesFrom(ArrayNode attributesNode,boolean replaceP){
  List<ReplaceableAttribute> attributeList=new ArrayList<ReplaceableAttribute>();
  for (int i=0; i < attributesNode.size(); i++) {
    ObjectNode objectNode=(ObjectNode)attributesNode.get(i);
    Iterator<String> itFieldName=objectNode.getFieldNames();
    while (itFieldName.hasNext()) {
      String key=itFieldName.next();
      JsonNode valueNode=objectNode.get(key);
      if (valueNode.isValueNode()) {
        attributeList.add(new ReplaceableAttribute(key,valueNode.asText(),replaceP));
      }
 else       if (valueNode.isArray()) {
        for (int j=0; j < valueNode.size(); j++) {
          JsonNode scalarValueNode=valueNode.get(j);
          attributeList.add(new ReplaceableAttribute(key,scalarValueNode.asText(),replaceP));
        }
      }
    }
  }
  return attributeList;
}
 

Example 23

From project build-info, under directory /build-info-client/src/main/java/org/jfrog/build/client/.

Source file: ArtifactoryBuildInfoClient.java

  21 
vote

/** 
 * @return A list of local repositories available for deployment.
 * @throws IOException On any connection error
 */
public List<String> getLocalRepositoriesKeys() throws IOException {
  List<String> repositories=new ArrayList<String>();
  PreemptiveHttpClient client=httpClient.getHttpClient();
  String localReposUrl=artifactoryUrl + LOCAL_REPOS_REST_URL;
  log.debug("Requesting local repositories list from: " + localReposUrl);
  HttpGet httpget=new HttpGet(localReposUrl);
  HttpResponse response=client.execute(httpget);
  StatusLine statusLine=response.getStatusLine();
  HttpEntity entity=response.getEntity();
  if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
    if (entity != null) {
      entity.consumeContent();
    }
    throwHttpIOException("Failed to obtain list of repositories:",statusLine);
  }
 else {
    if (entity != null) {
      repositories=new ArrayList<String>();
      InputStream content=entity.getContent();
      JsonParser parser;
      try {
        parser=httpClient.createJsonParser(content);
        JsonNode result=parser.readValueAsTree();
        log.debug("Repositories result = " + result);
        for (        JsonNode jsonNode : result) {
          String repositoryKey=jsonNode.get("key").getTextValue();
          repositories.add(repositoryKey);
        }
      }
  finally {
        if (content != null) {
          content.close();
        }
      }
    }
  }
  return repositories;
}
 

Example 24

From project cas, under directory /cas-server-support-oauth/src/main/java/org/jasig/cas/support/oauth/provider/impl/.

Source file: CasWrapperProvider20.java

  21 
vote

@Override protected UserProfile extractUserProfile(final String body){
  CasWrapperProfile userProfile=new CasWrapperProfile();
  JsonNode json=JsonHelper.getFirstNode(body);
  if (json != null) {
    userProfile.setId(JsonHelper.get(json,CasWrapperProfile.ID));
    json=json.get(CasWrapperProfile.ATTRIBUTES);
    if (json != null) {
      Iterator<JsonNode> nodes=json.iterator();
      while (nodes.hasNext()) {
        json=nodes.next();
        String attribute=json.getFieldNames().next();
        userProfile.addAttribute(attribute,JsonHelper.get(json,attribute));
      }
    }
  }
  return userProfile;
}
 

Example 25

From project cloudify, under directory /tools/src/main/java/org/cloudifysource/restDoclet/generation/.

Source file: Utils.java

  21 
vote

public static String getIndentJson(String body) throws JsonParseException, IOException {
  if (StringUtils.isBlank(body))   return null;
  StringWriter out=new StringWriter();
  JsonParser parser=null;
  JsonGenerator gen=null;
  try {
    JsonFactory fac=new JsonFactory();
    parser=fac.createJsonParser(new StringReader(body));
    ObjectMapper mapper=new ObjectMapper();
    JsonNode node=mapper.readTree(parser);
    gen=fac.createJsonGenerator(out);
    gen.useDefaultPrettyPrinter();
    mapper.writeTree(gen,node);
    gen.close();
    parser.close();
    return out.toString();
  }
  finally {
    out.close();
    if (gen != null) {
      gen.close();
    }
    if (parser != null) {
      parser.close();
    }
  }
}
 

Example 26

From project Couch-RQS, under directory /src/com/couchrqs/.

Source file: Queue.java

  21 
vote

/** 
 * Attempts to lock the documents - bulk-update them with a "lock" field.<br /> Returns the result of the bulk update. Some or all of the documents may not have been saved due to update conflict (some other process had already updated these docs).
 */
private ArrayList<JsonNode> lockDocuments(List<Document> docs,long visibilityTimeout) throws RQSException {
  final int bulkSize=docs.size() << 1;
  if (db.getBulkUpdatesLimit() < bulkSize)   db.setBulkUpdatesLimit(bulkSize);
  JsonNode lock=createLock(visibilityTimeout);
  try {
    for (    Document doc : docs) {
      ObjectNode json=(ObjectNode)doc.getJson();
      json.put("lock",lock);
      db.saveInBulk(doc);
    }
    return db.flushBulkUpdatesCache(false,true);
  }
 catch (  Exception e) {
    throw new RQSException(e);
  }
}
 

Example 27

From project gedcomx, under directory /enunciate-gedcomx-support/src/main/java/org/gedcomx/build/enunciate/.

Source file: GenerateExampleJsonMethod.java

  21 
vote

@Override protected void generateExampleJson(Element element,ObjectNode jsonNode,int maxDepth){
  if (element.isCollectionType() && ((DecoratedTypeMirror)element.getBareAccessorType()).isInstanceOf(HasJsonKey.class.getName())) {
    String jsonName=element.getJsonMemberName();
    ObjectNode on=JsonNodeFactory.instance.objectNode();
    JsonNode val=generateExampleJson(element.getBaseType(),"...",maxDepth);
    JsonNode ex;
    boolean isUnique=((DecoratedTypeMirror)element.getBareAccessorType()).isInstanceOf(HasUniqueJsonKey.class.getName());
    if (!isUnique) {
      ArrayNode exs=JsonNodeFactory.instance.arrayNode();
      exs.add(val);
      exs.add(WhateverNode.instance);
      ex=exs;
    }
 else {
      ex=val;
    }
    on.put("type1",ex);
    on.put("type2",ex);
    on.put("...",WhateverNode.instance);
    jsonNode.put(jsonName,on);
  }
 else {
    String simpleValue=getSimpleValue(element);
    if (simpleValue != null) {
      jsonNode.put(element.getJsonMemberName(),simpleValue);
    }
 else {
      super.generateExampleJson(element,jsonNode,maxDepth);
    }
  }
}
 

Example 28

From project android-xbmcremote-sandbox, under directory /src/org/xbmc/android/jsonrpc/io/audio/.

Source file: AlbumHandler.java

  19 
vote

@Override protected ContentValues[] parse(JsonNode result,ContentResolver resolver){
  final long now=System.currentTimeMillis();
  Log.d(TAG,"Building queries for album's drop and create.");
  final ArrayNode albums=(ArrayNode)result.get(AbstractCall.RESULT).get(AudioLibrary.GetAlbums.RESULTS);
  final ContentValues[] batch=new ContentValues[albums.size()];
  for (int i=0; i < albums.size(); i++) {
    final ObjectNode album=(ObjectNode)albums.get(i);
    batch[i]=new ContentValues();
    batch[i].put(SyncColumns.UPDATED,now);
    batch[i].put(Albums.ID,album.get(AudioModel.AlbumDetails.ALBUMID).getIntValue());
    batch[i].put(Albums.TITLE,album.get(AudioModel.AlbumDetails.TITLE).getTextValue());
    batch[i].put(Albums.PREFIX + Artists.ID,album.get(AudioModel.AlbumDetails.ARTISTID).getIntValue());
    batch[i].put(Albums.YEAR,album.get(AudioModel.AlbumDetails.YEAR).getIntValue());
  }
  Log.d(TAG,batch.length + " album queries built in " + (System.currentTimeMillis() - now)+ "ms.");
  return batch;
}
 

Example 29

From project Blueprint, under directory /blueprint-jackson-json/src/main/java/org/codemined/blueprint/impl/.

Source file: JsonTree.java

  19 
vote

@Override public List<JsonTree> getList(){
  if (!jsonNode.isArray()) {
    return null;
  }
  if (this.listElements == null) {
    this.listElements=new ArrayList<JsonTree>();
    for (    JsonNode node : jsonNode) {
      listElements.add(new JsonTree(node));
    }
  }
  return listElements;
}
 

Example 30

From project candlepin, under directory /src/main/java/org/candlepin/util/apicrawl/.

Source file: NonRecursiveBeanSerializer.java

  19 
vote

@Override public JsonNode getSchema(SerializerProvider arg0,Type arg1) throws JsonMappingException {
  if (!seenClasses.contains(arg1)) {
    seenClasses.add(arg1);
    return wrapped.getSchema(arg0,arg1);
  }
  return JsonSchema.getDefaultSchemaNode();
}
 

Example 31

From project email-preview, under directory /src/main/java/org/jasig/portlet/emailpreview/dao/demo/.

Source file: DemoAccountService.java

  19 
vote

/** 
 * Builds a fresh collection of messages.
 */
private List<EmailMessage> getEmailMessages(PortletRequest req){
  File jsonFile=new File(getClass().getResource(jsonLocation).getFile());
  List<EmailMessage> messages=new ArrayList<EmailMessage>();
  try {
    ObjectMapper mapper=new ObjectMapper();
    ArrayNode json=mapper.readValue(jsonFile,ArrayNode.class);
    for (    JsonNode msg : json) {
      long uid=msg.path("uid").getLongValue();
      String sender=msg.path("from").getTextValue();
      String subject=msg.path("subject").getTextValue();
      Date sentDate=new Date(msg.path("sentDate").getLongValue());
      boolean unread=msg.path("unread").getBooleanValue();
      boolean answered=false;
      boolean deleted=false;
      EmailMessageContent content=new EmailMessageContent(msg.path("body").getTextValue(),true);
      messages.add(new EmailMessage(messages.size(),uid,sender,subject,sentDate,unread,answered,deleted,false,"text/plain",content));
    }
  }
 catch (  Exception e) {
    log.error("Failed to load messages collection",e);
  }
  return messages;
}
 

Example 32

From project flume-twitter, under directory /src/main/java/st/happy_camper/flume/twitter/entity/.

Source file: Place.java

  19 
vote

/** 
 * @param path
 */
public Place(JsonNode json){
  id=json.path("id").getTextValue();
  name=json.path("name").getTextValue();
  fullName=json.path("full_name").getTextValue();
  url=json.path("url").getTextValue();
  placeType=json.path("place_type").getTextValue();
  country=json.path("country").getTextValue();
  countryCode=json.path("country_code").getTextValue();
  boundingBox=json.path("bounding_box").isNull() ? null : json.path("bounding_box").path("coordinates").toString();
  boundingBoxType=json.path("bounding_box").path("type").getTextValue();
  attributes=json.path("attributes").toString();
}