Java Code Examples for com.fasterxml.jackson.core.JsonParser#getText()

The following examples show how to use com.fasterxml.jackson.core.JsonParser#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanTable.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueSetString parsing
 */
public static Set<String> parseValueSetString(byte[] input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    Set<String> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      HashSet<String> collection=new HashSet<>();
      String item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=jacksonParser.getText();
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 2
Source File: JsonDateDeserializer.java    From pro-spring-boot with Apache License 2.0 5 votes vote down vote up
public Date deserialize(JsonParser jsonparser, DeserializationContext ctx) throws IOException, JsonProcessingException {
	String date = jsonparser.getText();
    try {
           return dateFormat.parse(date);
       } catch (ParseException e) {
           throw new RuntimeException(e);
       }
}
 
Example 3
Source File: BindBeanSharedPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueEnumTypeSet parsing
 */
protected HashSet<EnumType> parseValueEnumTypeSet(String input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    HashSet<EnumType> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      HashSet<EnumType> collection=new HashSet<>();
      EnumType item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
           {
            String tempEnum=jacksonParser.getText();
            item=StringUtils.hasText(tempEnum)?EnumType.valueOf(tempEnum):null;
          }
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 4
Source File: StudentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Student parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Student instance = new Student();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "location":
          // field location (mapped with "location")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.location=jacksonParser.getText();
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 5
Source File: Bean84ATable.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute columnMapIntegerString parsing
 */
public static Map<Integer, String> parseColumnMapIntegerString(byte[] input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    Map<Integer, String> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      HashMap<Integer, String> collection=new HashMap<>();
      Integer key=null;
      String value=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        jacksonParser.nextValue();
        key=jacksonParser.getIntValue();
        jacksonParser.nextValue();
        if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
          value=jacksonParser.getText();
        }
        collection.put(key, value);
        key=null;
        value=null;
        jacksonParser.nextToken();
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 6
Source File: ParseSupport.java    From curiostack with MIT License 5 votes vote down vote up
/** Parsers a double value out of the input. */
public static double parseDouble(JsonParser parser) throws IOException {
  JsonToken current = parser.currentToken();
  if (!current.isNumeric()) {
    String json = parser.getText();
    if (json.equals("NaN")) {
      return Double.NaN;
    } else if (json.equals("Infinity")) {
      return Double.POSITIVE_INFINITY;
    } else if (json.equals("-Infinity")) {
      return Double.NEGATIVE_INFINITY;
    }
  }
  try {
    // We don't use Double.parseDouble() here because that function simply
    // accepts all values. Here we readValue the value into a BigDecimal and do
    // explicit range check on it.
    BigDecimal value =
        new BigDecimal(
            parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
    if (value.compareTo(MAX_DOUBLE) > 0 || value.compareTo(MIN_DOUBLE) < 0) {
      throw new InvalidProtocolBufferException("Out of range double value: " + parser.getText());
    }
    return value.doubleValue();
  } catch (NumberFormatException e) {
    throw new InvalidProtocolBufferException("Not an double value: " + parser.getText());
  }
}
 
Example 7
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute stringList parsing
 */
protected List<String> parseStringList(String input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    List<String> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      ArrayList<String> collection=new ArrayList<>();
      String item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=jacksonParser.getText();
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 8
Source File: ChildBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Child parseOnJackson(JsonParser jacksonParser) throws Exception {
  Child instance = new Child();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "parentId":
          // field parentId (mapped with "parentId")
          instance.parentId=jacksonParser.getLongValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 9
Source File: BindBean63SharedPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueMapStringByte parsing
 */
protected Map<String, Byte> parseValueMapStringByte(String input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    Map<String, Byte> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      HashMap<String, Byte> collection=new HashMap<>();
      String key=null;
      Byte value=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        jacksonParser.nextValue();
        key=jacksonParser.getText();
        jacksonParser.nextValue();
        if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
          value=jacksonParser.getByteValue();
        }
        collection.put(key, value);
        key=null;
        value=null;
        jacksonParser.nextToken();
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 10
Source File: Bean8BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean8 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean8 instance = new Bean8();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "ignore2":
          // field ignore2 (mapped with "ignore2")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.ignore2=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 11
Source File: CommandResponseType.java    From mattermost4j with Apache License 2.0 4 votes vote down vote up
@Override
public CommandResponseType deserialize(JsonParser p, DeserializationContext ctxt)
    throws IOException {
  String code = p.getText();
  return CommandResponseType.of(code);
}
 
Example 12
Source File: PhoneNumberBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PhoneNumber parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  PhoneNumber instance = new PhoneNumber();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "actionType":
          // field actionType (mapped with "actionType")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            String tempEnum=jacksonParser.getText();
            instance.actionType=StringUtils.hasText(tempEnum)?ActionType.valueOf(tempEnum):null;
          }
        break;
        case "contactId":
          // field contactId (mapped with "contactId")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactId=jacksonParser.getText();
          }
        break;
        case "contactName":
          // field contactName (mapped with "contactName")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactName=jacksonParser.getText();
          }
        break;
        case "countryCode":
          // field countryCode (mapped with "countryCode")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.countryCode=jacksonParser.getText();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "number":
          // field number (mapped with "number")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.number=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 13
Source File: Bean1BindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean1 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean1 instance = new Bean1();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "adaptedBean3":
          // field adaptedBean3 (mapped with "adaptedBean3")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            // using type adapter bind.git49.Bean3Adapter
            instance.adaptedBean3=TypeAdapterUtils.toJava(Bean3Adapter.class, jacksonParser.getText());
          }
        break;
        case "bean2":
          // field bean2 (mapped with "bean2")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT) {
            instance.bean2=bean2BindMap.parseOnJackson(jacksonParser);
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 14
Source File: WebElementDeserializer.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Override
public Supplier<Optional<WebElement>> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
    String locator = p.getText();
    return ElementUtil.getElement(locator, searchActions);
}
 
Example 15
Source File: Bean81UBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean81U parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean81U instance = new Bean81U();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "valueInteger":
          // field valueInteger (mapped with "valueInteger")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueInteger=jacksonParser.getIntValue();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "valueMapStringInteger":
          // field valueMapStringInteger (mapped with "valueMapStringInteger")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            HashMap<String, Integer> collection=new HashMap<>();
            String key=null;
            Integer value=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              jacksonParser.nextValue();
              key=jacksonParser.getText();
              jacksonParser.nextValue();
              if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
                value=jacksonParser.getIntValue();
              }
              collection.put(key, value);
              key=null;
              value=null;
              jacksonParser.nextToken();
            }
            instance.valueMapStringInteger=collection;
          }
        break;
        case "valueByteArray":
          // field valueByteArray (mapped with "valueByteArray")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueByteArray=jacksonParser.getBinaryValue();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 16
Source File: ResponseBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Response parseOnJackson(JsonParser jacksonParser) throws Exception {
  Response instance = new Response();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "status":
          // field status (mapped with "status")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.status=jacksonParser.getText();
          }
        break;
        case "users":
          // field users (mapped with "users")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            ArrayList<User> collection=new ArrayList<>();
            User item=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
                item=null;
              } else {
                item=userBindMap.parseOnJackson(jacksonParser);
              }
              collection.add(item);
            }
            instance.users=collection;
          }
        break;
        case "is_real_json":
          // field isRealJson (mapped with "is_real_json")
          instance.isRealJson=jacksonParser.getBooleanValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 17
Source File: OpenRtbJsonReader.java    From openrtb with Apache License 2.0 4 votes vote down vote up
protected void readBidRequestField(JsonParser par, BidRequest.Builder req, String fieldName)
    throws IOException {
  switch (fieldName) {
    case "id":
      req.setId(par.getText());
      break;
    case "imp":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addImp(readImp(par));
      }
      break;
    case "site":
      req.setSite(readSite(par));
      break;
    case "app":
      req.setApp(readApp(par));
      break;
    case "device":
      req.setDevice(readDevice(par));
      break;
    case "user":
      req.setUser(readUser(par));
      break;
    case "test":
      req.setTest(par.getValueAsBoolean());
      break;
    case "at": {
        AuctionType value = AuctionType.forNumber(par.getIntValue());
        if (checkEnum(value)) {
          req.setAt(value);
        }
      }
      break;
    case "tmax":
      req.setTmax(par.getIntValue());
      break;
    case "wseat":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addWseat(par.getText());
      }
      break;
    case "allimps":
      req.setAllimps(par.getValueAsBoolean());
      break;
    case "cur":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addCur(par.getText());
      }
      break;
    case "bcat":
      for (startArray(par); endArray(par); par.nextToken()) {
        String cat = par.getText();
        if (checkContentCategory(cat)) {
          req.addBcat(cat);
        }
      }
      break;
    case "badv":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addBadv(par.getText());
      }
      break;
    case "regs":
      req.setRegs(readRegs(par));
      break;
    case "bapp":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addBapp(par.getText());
      }
      break;
    case "bseat":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addBseat(par.getText());
      }
      break;
    case "wlang":
      for (startArray(par); endArray(par); par.nextToken()) {
        req.addWlang(par.getText());
      }
      break;
    case "source":
      req.setSource(readSource(par));
      break;
    default:
      readOther(req, par, fieldName);
  }
}
 
Example 18
Source File: Sequence.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public LogicalOperator deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
    JsonProcessingException {
  ObjectIdGenerator<Integer> idGenerator = new ObjectIdGenerators.IntSequenceGenerator();
  JsonLocation start = jp.getCurrentLocation();
  JsonToken t = jp.getCurrentToken();
  LogicalOperator parent = null;
  LogicalOperator first = null;
  LogicalOperator prev = null;
  Integer id = null;

  while (true) {
    String fieldName = jp.getText();
    t = jp.nextToken();
    switch (fieldName) { // switch on field names.
    case "@id":
      id = _parseIntPrimitive(jp, ctxt);
      break;
    case "input":
      JavaType tp = ctxt.constructType(LogicalOperator.class);
      JsonDeserializer<Object> d = ctxt.findRootValueDeserializer(tp);
      parent = (LogicalOperator) d.deserialize(jp, ctxt);
      break;

    case "do":
      if (!jp.isExpectedStartArrayToken()) {
        throwE(
            jp,
            "The do parameter of sequence should be an array of SimpleOperators.  Expected a JsonToken.START_ARRAY token but received a "
                + t.name() + "token.");
      }

      int pos = 0;
      while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
        // logger.debug("Reading sequence child {}.", pos);
        JsonLocation l = jp.getCurrentLocation(); // get current location
                                                  // first so we can
                                                  // correctly reference the
                                                  // start of the object in
                                                  // the case that the type
                                                  // is wrong.
        LogicalOperator o = jp.readValueAs(LogicalOperator.class);

        if (pos == 0) {
          if (!(o instanceof SingleInputOperator) && !(o instanceof SourceOperator)) {
            throwE(
                l,
                "The first operator in a sequence must be either a ZeroInput or SingleInput operator.  The provided first operator was not. It was of type "
                    + o.getClass().getName());
          }
          first = o;
        } else {
          if (!(o instanceof SingleInputOperator)) {
            throwE(l, "All operators after the first must be single input operators.  The operator at position "
                + pos + " was not. It was of type " + o.getClass().getName());
          }
          SingleInputOperator now = (SingleInputOperator) o;
          now.setInput(prev);
        }
        prev = o;

        pos++;
      }
      break;
    default:
      throwE(jp, "Unknown field name provided for Sequence: " + jp.getText());
    }

    t = jp.nextToken();
    if (t == JsonToken.END_OBJECT) {
      break;
    }
  }

  if (first == null) {
    throwE(start, "A sequence must include at least one operator.");
  }
  if ((parent == null && first instanceof SingleInputOperator)
      || (parent != null && first instanceof SourceOperator)) {
    throwE(start,
        "A sequence must either start with a ZeroInputOperator or have a provided input. It cannot have both or neither.");
  }

  if (parent != null && first instanceof SingleInputOperator) {
    ((SingleInputOperator) first).setInput(parent);
  }

  // set input reference.
  if (id != null) {

    ReadableObjectId rid = ctxt.findObjectId(id, idGenerator, null);
    rid.bindItem(prev);
    // logger.debug("Binding id {} to item {}.", rid.id, rid.item);

  }

  return first;
}
 
Example 19
Source File: PersonBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJackson(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "birthday":
          // field birthday (mapped with "birthday")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthday=DateUtils.read(jacksonParser.getText());
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "parent":
          // field parent (mapped with "parent")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT) {
            instance.parent=personBindMap.parseOnJackson(jacksonParser);
          }
        break;
        case "surname":
          // field surname (mapped with "surname")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.surname=jacksonParser.getText();
          }
        break;
        case "tags":
          // field tags (mapped with "tags")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            ArrayList<String> collection=new ArrayList<>();
            String item=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
                item=null;
              } else {
                item=jacksonParser.getText();
              }
              collection.add(item);
            }
            instance.tags=collection;
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 20
Source File: MembersResource.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
protected LBMember jsonToMember(String json) throws IOException {
    MappingJsonFactory f = new MappingJsonFactory();
    JsonParser jp;
    LBMember member = new LBMember();
    
    try {
        jp = f.createJsonParser(json);
    } 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.equals("id")) {
            member.id = jp.getText();
            continue;
        } else
        if (n.equals("address")) {
            member.address = IPv4.toIPv4Address(jp.getText());
            continue;
        } else
        if (n.equals("port")) {
            member.port = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("connection_limit")) {
            member.connectionLimit = Integer.parseInt(jp.getText());
            continue;
        } else
        if (n.equals("admin_state")) {
            member.adminState = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("status")) {
            member.status = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("pool_id")) {
            member.poolId = jp.getText();
            continue;
        } 
        
        log.warn("Unrecognized field {} in " +
                "parsing Members", 
                jp.getText());
    }
    jp.close();

    return member;
}