Пример #1
0
 public static Integer jsonValueToInteger(JSONValue jsonValue) {
   if (jsonValue != null) {
     JSONNumber jsonNumber = jsonValue.isNumber();
     if (jsonNumber != null) {
       return (int) jsonNumber.doubleValue();
     }
   }
   return null;
 }
Пример #2
0
 public static Long jsonValueToLong(JSONValue jsonValue) {
   if (jsonValue != null) {
     JSONNumber jsonNumber = jsonValue.isNumber();
     if (jsonNumber != null) {
       return (long) jsonNumber.doubleValue();
     }
   }
   return null;
 }
Пример #3
0
 public static Double jsonValueToDouble(JSONValue jsonValue) {
   if (jsonValue != null) {
     JSONNumber jsonNumber = jsonValue.isNumber();
     if (jsonNumber != null) {
       return jsonNumber.doubleValue();
     }
   }
   return null;
 }
Пример #4
0
 public static Float jsonValueToFloat(JSONValue jsonValue) {
   if (jsonValue != null) {
     JSONNumber jsonNumber = jsonValue.isNumber();
     if (jsonNumber != null) {
       return (float) jsonNumber.doubleValue();
     }
   }
   return null;
 }
 public static double toDouble(JSONValue value) {
   JSONNumber number = value.isNumber();
   if (number == null) {
     JSONString val = value.isString();
     if (val != null) {
       try {
         return Double.parseDouble(val.stringValue());
       } catch (NumberFormatException e) {
         // just through exception below
       }
     }
     throw new DecodingException("Expected a json number, but was given: " + value);
   }
   return number.doubleValue();
 }
 @PatchMethod
 static String toString(JSONNumber jsonNumber) {
   double doubleValue = jsonNumber.doubleValue();
   if (Math.floor(doubleValue) == doubleValue) {
     // the number is an integer
     return String.valueOf((int) doubleValue);
   } else {
     return String.valueOf(doubleValue);
   }
 }
 @Override
 public Date decode(JSONValue value) throws DecodingException {
   if (value == null || value.isNull() != null) {
     return null;
   }
   String format = Defaults.getDateFormat();
   if (format == null) {
     JSONNumber num = value.isNumber();
     if (num == null) {
       throw new DecodingException("Expected a json number, but was given: " + value);
     }
     return new Date((long) num.doubleValue());
   }
   JSONString str = value.isString();
   if (str == null) {
     throw new DecodingException("Expected a json string, but was given: " + value);
   }
   return DateTimeFormat.getFormat(format).parse(str.stringValue());
 }
Пример #8
0
  public void parseJSON(JSONObject sourceObj) {
    JSONString type = (JSONString) sourceObj.get("type");
    JSONString componentID = (JSONString) sourceObj.get("componentID");
    JSONString componentDescription = (JSONString) sourceObj.get("componentDescription");

    JSONString fileName = (JSONString) sourceObj.get("fileName");
    JSONString loadFunction = (JSONString) sourceObj.get("loadFunction");
    JSONNumber xcoor = (JSONNumber) sourceObj.get("xcoor");
    JSONNumber ycoor = (JSONNumber) sourceObj.get("ycoor");
    setComponentID(componentID.stringValue());
    setComponentDescription(componentDescription.stringValue());
    setFileName(fileName.stringValue());
    setLeft(xcoor.doubleValue());
    setTop(ycoor.doubleValue());

    JSONArray ports = (JSONArray) sourceObj.get("ports");
    for (int i = 0; i < ports.size(); i++) {
      JSONObject portobj = (JSONObject) ports.get(i);
      JSONString porttype = (JSONString) portobj.get("porttype");
      // JSONString dataSet = (JSONString) portobj.get("dataSet");
      JSONArray dataDefinition = (JSONArray) portobj.get("dataSet");
      for (int j = 0; j < dataDefinition.size(); j++) {
        JSONObject entry = (JSONObject) dataDefinition.get(j);
        JSONNumber order = (JSONNumber) entry.get("order");
        JSONString fieldName = (JSONString) entry.get("fieldName");
        JSONString fieldType = (JSONString) entry.get("fieldType");
        getPort(porttype.stringValue())
            .getDataSet()
            .add(
                new DataDefinitionEntry(
                    Integer.parseInt(order.toString()),
                    fieldName.stringValue(),
                    fieldType.stringValue()));
      }
    }
  }