Package com.fasterxml.jackson.core

Examples of com.fasterxml.jackson.core.JsonParser


  }

  /** Helper to parse an input stream into a map */
  private HashMap<String, String> parseToMap(final InputStream is)
    throws Exception {
    JsonParser jp = JSON.parseToStream(is);
    HashMap<String, String> map = new HashMap<String, String>();
    String field = "";
    String value;
    while (jp.nextToken() != null) {
      if (jp.getCurrentToken() == JsonToken.FIELD_NAME &&
          jp.getCurrentName() != null) {
        field = jp.getCurrentName();
      } else if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
        value = jp.getText();
        map.put(field, value);
      }       
    }
    return map;
  }
View Full Code Here


    }
  }
 
  private String getStatusFromJsonResponse(String responsbody) throws ManifoldCFException {
    try {
      JsonParser parser = new JsonFactory().createJsonParser(responsbody);
      while (parser.nextToken() != JsonToken.END_OBJECT)
      {
        String name = parser.getCurrentName();
        if("status".equalsIgnoreCase(name)){
          parser.nextToken();
          return parser.getText();
        }
      }
    } catch (JsonParseException e) {
      throw new ManifoldCFException(e);
    } catch (IOException e) {
View Full Code Here

     * @return The name of the OFFlowMod, null if not found
     * @throws IOException If there was an error parsing the JSON
     */
    public static String getEntryNameFromJson(String fmJson) throws IOException{
        MappingJsonFactory f = new MappingJsonFactory();
        JsonParser jp;
       
        try {
            jp = f.createJsonParser(fmJson);
        } catch (JsonParseException e) {
            throw new IOException(e);
        }
       
        jp.nextToken();
        if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
            throw new IOException("Expected START_OBJECT");
        }
       
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
                throw new IOException("Expected FIELD_NAME");
            }
           
            String n = jp.getCurrentName();
            jp.nextToken();
            if (jp.getText().equals(""))
                continue;
           
            if (n == "name")
                return jp.getText();
        }
       
        return null;
    }
View Full Code Here

     * @throws IOException If there was an error parsing the JSON
     */
    public static Map<String, Object> jsonToStorageEntry(String fmJson) throws IOException {
        Map<String, Object> entry = new HashMap<String, Object>();
        MappingJsonFactory f = new MappingJsonFactory();
        JsonParser jp;
       
        try {
            jp = f.createJsonParser(fmJson);
        } catch (JsonParseException e) {
            throw new IOException(e);
        }
       
        jp.nextToken();
        if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
            throw new IOException("Expected START_OBJECT");
        }
       
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
                throw new IOException("Expected FIELD_NAME");
            }
           
            String n = jp.getCurrentName();
            jp.nextToken();
            if (jp.getText().equals(""))
                continue;
           
            if (n == "name")
                entry.put(StaticFlowEntryPusher.COLUMN_NAME, jp.getText());
            else if (n == "switch")
                entry.put(StaticFlowEntryPusher.COLUMN_SWITCH, jp.getText());
            else if (n == "actions")
                entry.put(StaticFlowEntryPusher.COLUMN_ACTIONS, jp.getText());
            else if (n == "priority")
                entry.put(StaticFlowEntryPusher.COLUMN_PRIORITY, jp.getText());
            else if (n == "active")
                entry.put(StaticFlowEntryPusher.COLUMN_ACTIVE, jp.getText());
            else if (n == "wildcards")
                entry.put(StaticFlowEntryPusher.COLUMN_WILDCARD, jp.getText());
            else if (n == "ingress-port")
                entry.put(StaticFlowEntryPusher.COLUMN_IN_PORT, jp.getText());
            else if (n == "src-mac")
                entry.put(StaticFlowEntryPusher.COLUMN_DL_SRC, jp.getText());
            else if (n == "dst-mac")
                entry.put(StaticFlowEntryPusher.COLUMN_DL_DST, jp.getText());
            else if (n == "vlan-id")
                entry.put(StaticFlowEntryPusher.COLUMN_DL_VLAN, jp.getText());
            else if (n == "vlan-priority")
                entry.put(StaticFlowEntryPusher.COLUMN_DL_VLAN_PCP, jp.getText());
            else if (n == "ether-type")
                entry.put(StaticFlowEntryPusher.COLUMN_DL_TYPE, jp.getText());
            else if (n == "tos-bits")
                entry.put(StaticFlowEntryPusher.COLUMN_NW_TOS, jp.getText());
            else if (n == "protocol")
                entry.put(StaticFlowEntryPusher.COLUMN_NW_PROTO, jp.getText());
            else if (n == "src-ip")
                entry.put(StaticFlowEntryPusher.COLUMN_NW_SRC, jp.getText());
            else if (n == "dst-ip")
                entry.put(StaticFlowEntryPusher.COLUMN_NW_DST, jp.getText());
            else if (n == "src-port")
                entry.put(StaticFlowEntryPusher.COLUMN_TP_SRC, jp.getText());
            else if (n == "dst-port")
                entry.put(StaticFlowEntryPusher.COLUMN_TP_DST, jp.getText());
        }
       
        return entry;
    }
View Full Code Here

  @Override
  public DataMap bytesToMap(byte[] input) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(input);
      return parser.parse(jsonParser, DataMap.class);
    }
View Full Code Here

  @Override
  public DataMap stringToMap(String input) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(input);
      return parser.parse(jsonParser, DataMap.class);
    }
View Full Code Here

  @Override
  public DataList bytesToList(byte[] input) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(input);
      return parser.parse(jsonParser, DataList.class);
    }
View Full Code Here

  @Override
  public DataList stringToList(String input) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(input);
      return parser.parse(jsonParser, DataList.class);
    }
View Full Code Here

  @Override
  public DataMap readMap(InputStream in) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(in);
      return parser.parse(jsonParser, DataMap.class);
    }
View Full Code Here

  @Override
  public DataMap readMap(Reader in) throws IOException
  {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try
    {
      jsonParser = _jsonFactory.createParser(in);
      return parser.parse(jsonParser, DataMap.class);
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.core.JsonParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.