Example usage for com.google.gson.stream JsonReader nextString

List of usage examples for com.google.gson.stream JsonReader nextString

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader nextString.

Prototype

public String nextString() throws IOException 

Source Link

Document

Returns the com.google.gson.stream.JsonToken#STRING string value of the next token, consuming it.

Usage

From source file:org.komodo.rest.relational.json.SearcherAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*ww  w  . j a v a 2 s .  c  o m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoSearcherAttributes read(final JsonReader in) throws IOException {
    final KomodoSearcherAttributes searcherAttr = createEntity();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        if (readPath(in, name, searcherAttr) != null)
            continue;

        switch (name) {
        case KomodoSearcherAttributes.SEARCH_NAME_LABEL:
            searcherAttr.setSearchName(in.nextString());
            break;
        case KomodoSearcherAttributes.TYPE_LABEL:
            searcherAttr.setType(in.nextString());
            break;
        case KomodoSearcherAttributes.PARENT_LABEL:
            searcherAttr.setParent(in.nextString());
            break;
        case KomodoSearcherAttributes.ANCESTOR_LABEL:
            searcherAttr.setAncestor(in.nextString());
            break;
        case KomodoSearcherAttributes.CONTAINS_LABEL:
            searcherAttr.setContains(in.nextString());
            break;
        case KomodoSearcherAttributes.OBJECT_NAME_LABEL:
            searcherAttr.setObjectName(in.nextString());
            break;
        case KomodoSearcherAttributes.PARAMETERS_LABEL:
            Map<String, String> parameters = BUILDER.fromJson(in, Map.class);
            for (Map.Entry<String, String> parameter : parameters.entrySet()) {
                searcherAttr.setParameter(parameter.getKey(), parameter.getValue());
            }
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return searcherAttr;
}

From source file:org.komodo.rest.relational.json.StatusObjectSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*w w  w  .  j a v a  2s . c  o  m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStatusObject read(final JsonReader in) throws IOException {
    final KomodoStatusObject status = new KomodoStatusObject();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoStatusObject.TITLE_LABEL:
            status.setTitle(in.nextString());
            break;
        case KomodoStatusObject.INFO_LABEL:
            Map<String, String> attributes = BUILDER.fromJson(in, Map.class);
            status.setAttributes(attributes);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return status;
}

From source file:org.komodo.rest.relational.json.StorageAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w ww.jav  a 2  s  .com*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStorageAttributes read(final JsonReader in) throws IOException {
    final KomodoStorageAttributes storageAttr = new KomodoStorageAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        if (readContent(in, storageAttr, name) != null)
            continue;

        switch (name) {
        case KomodoStorageAttributes.STORAGE_TYPE_LABEL:
            storageAttr.setStorageType(in.nextString());
            break;
        case KomodoStorageAttributes.ARTIFACT_PATH_LABEL:
            storageAttr.setArtifactPath(in.nextString());
            break;
        case KomodoStorageAttributes.PARAMETERS_LABEL:
            Map<String, String> parameters = BUILDER.fromJson(in, Map.class);
            for (Map.Entry<String, String> parameter : parameters.entrySet()) {
                storageAttr.setParameter(parameter.getKey(), parameter.getValue());
            }
            break;
        case KomodoStorageAttributes.DOCUMENT_TYPE_LABEL:
            String docTypeValue = in.nextString();
            DocumentType docType = DocumentType.documentType(docTypeValue);
            storageAttr.setDocumentType(docType);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageAttr;
}

From source file:org.komodo.rest.relational.json.StorageTypeDescriptorSerializer.java

License:Open Source License

@Override
public RestStorageTypeDescriptor read(JsonReader in) throws IOException {
    final RestStorageTypeDescriptor storageTypeDescriptor = new RestStorageTypeDescriptor();
    in.beginObject();//from w  w  w . ja v  a2  s  .  c  o m

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageTypeDescriptor.NAME_LABEL:
            storageTypeDescriptor.setName(in.nextString());
            break;
        case RestStorageTypeDescriptor.DESCRIPTION_LABEL:
            storageTypeDescriptor.setDescription(in.nextString());
            break;
        case RestStorageTypeDescriptor.REQUIRED_LABEL:
            storageTypeDescriptor.setRequired(in.nextBoolean());
            break;
        case RestStorageTypeDescriptor.ENCODED_LABEL:
            storageTypeDescriptor.setEncoded(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageTypeDescriptor;
}

From source file:org.komodo.rest.relational.json.StorageTypeSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//  w w w.j  av a  2 s. c o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestStorageType read(final JsonReader in) throws IOException {
    final RestStorageType storageType = new RestStorageType();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageType.NAME_LABEL:
            storageType.setName(in.nextString());
            break;
        case RestStorageType.DESCRIPTION_LABEL:
            storageType.setDescription(in.nextString());
            break;
        case RestStorageType.DESCRIPTORS_LABEL:
            RestStorageTypeDescriptor[] descriptors = BUILDER.fromJson(in, RestStorageTypeDescriptor[].class);
            storageType.setDescriptors(descriptors);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageType;
}

From source file:org.komodo.rest.relational.json.TeiidAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww  w.  j  a  va 2  s.c  o m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoTeiidAttributes read(final JsonReader in) throws IOException {
    final KomodoTeiidAttributes teiidAttrs = new KomodoTeiidAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoTeiidAttributes.ADMIN_USER_LABEL:
            teiidAttrs.setAdminUser(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PASSWD_LABEL:
            teiidAttrs.setAdminPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PORT_LABEL:
            teiidAttrs.setAdminPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.ADMIN_SECURE_LABEL:
            teiidAttrs.setAdminSecure(in.nextBoolean());
            break;
        case KomodoTeiidAttributes.JDBC_USER_LABEL:
            teiidAttrs.setJdbcUser(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PASSWD_LABEL:
            teiidAttrs.setJdbcPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PORT_LABEL:
            teiidAttrs.setJdbcPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.JDBC_SECURE_LABEL:
            teiidAttrs.setJdbcSecure(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return teiidAttrs;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from w  w w.  j a v a 2s  .  c o  m
 *
 * @see org.komodo.rest.relational.json.AbstractEntitySerializer#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatus read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatus entity = createEntity();

    beginRead(in);

    while (in.hasNext()) {
        final String name = in.nextName();

        if (RestTeiidVdbStatus.VDBS_LABEL.equals(name)) {
            final RestTeiidVdbStatusVdb[] vdbStatuses = BUILDER.fromJson(in, RestTeiidVdbStatusVdb[].class);
            entity.setVdbProperties(Arrays.asList(vdbStatuses));
        } else if (LINKS.equals(name))
            readLinks(in, entity);
        else {
            JsonToken token = in.peek();
            switch (token) {
            case BOOLEAN:
                entity.addTuple(name, in.nextBoolean());
                break;
            case NUMBER:
                entity.addTuple(name, in.nextInt());
                break;
            case STRING:
                entity.addTuple(name, in.nextString());
                break;
            case NULL:
                in.nextNull();
                entity.addTuple(name, null);
                break;
            case BEGIN_ARRAY:
                final String[] value = BUILDER.fromJson(in, String[].class);
                entity.addTuple(name, value);
                break;
            default:
                throw new IOException(Messages.getString(Messages.Error.UNEXPECTED_JSON_TOKEN, name));
            }
        }
    }

    if (!isComplete(entity)) {
        throw new IOException(Messages.getString(INCOMPLETE_JSON, getClass().getSimpleName()));
    }

    endRead(in);
    return entity;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusVdbSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w  w . j  a va  2 s.  com*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatusVdb read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatusVdb vdb = new RestTeiidVdbStatusVdb();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_NAME:
            vdb.setName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_DEPLOYED_NAME:
            vdb.setDeployedName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_VERSION:
            vdb.setVersion(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ACTIVE:
            vdb.setActive(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_LOADING:
            vdb.setLoading(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_FAILED:
            vdb.setFailed(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ERROR:
            final String[] errors = BUILDER.fromJson(in, String[].class);
            vdb.setErrors(Arrays.asList(errors));
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return vdb;
}

From source file:org.komodo.rest.relational.json.VdbUpdateAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w w  . j  a  va  2  s.  c o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoVdbUpdateAttributes read(final JsonReader in) throws IOException {
    final KomodoVdbUpdateAttributes updateAttrs = new KomodoVdbUpdateAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoVdbUpdateAttributes.VDB_NAME_LABEL:
            updateAttrs.setVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.MODEL_NAME_LABEL:
            updateAttrs.setModelName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_VDB_NAME_LABEL:
            updateAttrs.setTeiidVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_MODEL_NAME_LABEL:
            updateAttrs.setTeiidModelName(in.nextString());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return updateAttrs;
}

From source file:org.lanternpowered.server.data.persistence.json.JsonDataFormat.java

License:MIT License

private static Object readString(JsonReader reader) throws IOException {
    final String value = reader.nextString();
    if (DOUBLE.matcher(value).matches()) {
        return Double.parseDouble(value.substring(0, value.length() - 1));
    } else if (FLOAT.matcher(value).matches()) {
        return Float.parseFloat(value.substring(0, value.length() - 1));
    } else if (LONG.matcher(value).matches()) {
        return Long.parseLong(value.substring(0, value.length() - 1));
    } else if (SHORT.matcher(value).matches()) {
        return Short.parseShort(value.substring(0, value.length() - 1));
    } else if (BYTE.matcher(value).matches()) {
        return Byte.parseByte(value.substring(0, value.length() - 1));
    } else if (INTEGER.matcher(value).matches()) {
        return Integer.parseInt(value);
    } else if (DOUBLE_UNTYPED.matcher(value).matches()) {
        return Double.parseDouble(value);
    } else {/*from   w ww. ja v  a2s  . co  m*/
        if ("true".equalsIgnoreCase(value)) {
            return true;
        } else if ("false".equalsIgnoreCase(value)) {
            return false;
        }
        return value;
    }
}