Package elemental.json

Examples of elemental.json.JsonException


    }

    public static Object decodeCustomType(Type targetType, JsonValue value,
            ConnectorTracker connectorTracker) {
        if (isInternalType(targetType)) {
            throw new JsonException("decodeCustomType cannot be used for "
                    + targetType + ", which is an internal type");
        }

        // Try to decode object using fields
        if (value.getType() == JsonType.NULL) {
View Full Code Here


     */
    public static Object decodeInternalType(Type targetType,
            boolean restrictToInternalTypes, JsonValue encodedJsonValue,
            ConnectorTracker connectorTracker) {
        if (!isInternalType(targetType)) {
            throw new JsonException("Type " + targetType
                    + " is not a supported internal type.");
        }
        String transportType = getInternalTransportType(targetType);

        if (encodedJsonValue.getType() == JsonType.NULL) {
            return null;
        } else if (targetType == Void.class) {
            throw new JsonException(
                    "Something other than null was encoded for a null type");
        }

        // UidlValue
        if (targetType == UidlValue.class) {
            return decodeUidlValue((JsonArray) encodedJsonValue,
                    connectorTracker);
        }

        // Collections
        if (JsonConstants.VTYPE_LIST.equals(transportType)) {
            return decodeList(targetType, restrictToInternalTypes,
                    (JsonArray) encodedJsonValue, connectorTracker);
        } else if (JsonConstants.VTYPE_SET.equals(transportType)) {
            return decodeSet(targetType, restrictToInternalTypes,
                    (JsonArray) encodedJsonValue, connectorTracker);
        } else if (JsonConstants.VTYPE_MAP.equals(transportType)) {
            return decodeMap(targetType, restrictToInternalTypes,
                    encodedJsonValue, connectorTracker);
        }

        // Arrays
        if (JsonConstants.VTYPE_ARRAY.equals(transportType)) {

            return decodeObjectArray(targetType, (JsonArray) encodedJsonValue,
                    connectorTracker);

        } else if (JsonConstants.VTYPE_STRINGARRAY.equals(transportType)) {
            return decodeStringArray((JsonArray) encodedJsonValue);
        }

        // Special Vaadin types

        if (JsonConstants.VTYPE_CONNECTOR.equals(transportType)) {
            return connectorTracker.getConnector(encodedJsonValue.asString());
        }

        // Legacy types

        if (JsonConstants.VTYPE_STRING.equals(transportType)) {
            return encodedJsonValue.asString();
        } else if (JsonConstants.VTYPE_INTEGER.equals(transportType)) {
            return (int) encodedJsonValue.asNumber();
        } else if (JsonConstants.VTYPE_LONG.equals(transportType)) {
            return (long) encodedJsonValue.asNumber();
        } else if (JsonConstants.VTYPE_FLOAT.equals(transportType)) {
            return (float) encodedJsonValue.asNumber();
        } else if (JsonConstants.VTYPE_DOUBLE.equals(transportType)) {
            return encodedJsonValue.asNumber();
        } else if (JsonConstants.VTYPE_BOOLEAN.equals(transportType)) {
            return encodedJsonValue.asBoolean();
        }

        throw new JsonException("Unknown type " + transportType);
    }
View Full Code Here

                // toReturn.
                return encodeObject(value, (Class<?>) valueType,
                        (JsonObject) diffState, connectorTracker);
            }
        } else {
            throw new JsonException("Can not encode type " + valueType);
        }
        return new EncodeResult(toReturn);
    }
View Full Code Here

            // Encode using the given type
            EncodeResult encodeResult = encode(o, null, childType,
                    connectorTracker);
            return encodeResult.getEncodedValue();
        } else {
            throw new JsonException("Collection is missing generics");
        }
    }
View Full Code Here

        if (mapType instanceof ParameterizedType) {
            keyType = ((ParameterizedType) mapType).getActualTypeArguments()[0];
            valueType = ((ParameterizedType) mapType).getActualTypeArguments()[1];
        } else {
            throw new JsonException("Map is missing generics");
        }

        if (map.isEmpty()) {
            // Client -> server encodes empty map as an empty array because of
            // #8906. Do the same for server -> client to maintain symmetry.
View Full Code Here

    private LegacyChangeVariablesInvocation parseLegacyChangeVariablesInvocation(
            String connectorId, String interfaceName, String methodName,
            LegacyChangeVariablesInvocation previousInvocation,
            JsonArray parametersJson, ConnectorTracker connectorTracker) {
        if (parametersJson.length() != 2) {
            throw new JsonException(
                    "Invalid parameters in legacy change variables call. Expected 2, was "
                            + parametersJson.length());
        }
        String variableName = parametersJson.getString(0);
        UidlValue uidlValue = (UidlValue) JsonCodec.decodeInternalType(
View Full Code Here

  public <T extends JsonValue> T parse(String jsonString) throws JsonException {
    try {
      return parse0(jsonString);
    } catch (Exception e) {
      throw new JsonException("Can't parse " + jsonString);
    }
  }
View Full Code Here

    while ((pos < n) && ((len = read(buffer, pos, n - pos)) != -1)) {
      pos += len;
    }

    if (pos < n) {
      throw new JsonException("TODO"/* TODO(knorton): Add message. */);
    }

    return String.valueOf(buffer);
  }
View Full Code Here

    while (true) {
      c = next();
      switch (c) {
        case '\r':
        case '\n':
          throw new JsonException("");
        case '\\':
          c = next();
          switch (c) {
            case 'b':
              buffer.append('\b');
View Full Code Here

             case ']':
               return array;
             case ',':
               break;
             default:
               throw new JsonException("Invalid array: expected , or ]");
           }
       }
     }
   }
View Full Code Here

TOP

Related Classes of elemental.json.JsonException

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.