Example usage for com.google.gson JsonElement getAsBoolean

List of usage examples for com.google.gson JsonElement getAsBoolean

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsBoolean.

Prototype

public boolean getAsBoolean() 

Source Link

Document

convenience method to get this element as a boolean value.

Usage

From source file:org.waveprotocol.box.server.rpc.proto.RpcFinishedProtoImpl.java

License:Apache License

@Override
public void fromGson(JsonElement json, Gson gson, RawStringData raw) throws GsonException {
    JsonObject jsonObject = json.getAsJsonObject();
    // NOTE: always check with has(...) as the json might not have all required
    // fields set; however these (obviously) will need to be set by other means
    // before accessing this object.
    invalidateAll();/*from ww w . j av  a  2 s.  c  o  m*/

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("1")) {
        JsonElement elem = jsonObject.get("1");
        setFailed(elem.getAsBoolean());
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("2")) {
        JsonElement elem = jsonObject.get("2");
        if (!elem.isJsonNull()) {
            setErrorText(elem.getAsString());
        }
    }
}

From source file:org.waveprotocol.wave.federation.gson.ProtocolWaveletOperationGsonImpl.java

License:Apache License

@Override
public void fromGson(JsonElement json, Gson gson, RawStringData raw) throws GsonException {
    reset();//from w  ww  .  j  ava2s.c o m
    JsonObject jsonObject = json.getAsJsonObject();
    // NOTE: always check with has(...) as the json might not have all required
    // fields set.

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("1")) {
        JsonElement elem = jsonObject.get("1");
        if (!elem.isJsonNull()) {

            /**
             * Licensed to the Apache Software Foundation (ASF) under one
             * or more contributor license agreements. See the NOTICE file
             * distributed with this work for additional information
             * regarding copyright ownership. The ASF licenses this file
             * to you under the Apache License, Version 2.0 (the
             * "License"); you may not use this file except in compliance
             * with the License. You may obtain a copy of the License at
             *
             * http://www.apache.org/licenses/LICENSE-2.0
             *
             * Unless required by applicable law or agreed to in writing,
             * software distributed under the License is distributed on an
             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
             * KIND, either express or implied. See the License for the
             * specific language governing permissions and limitations
             * under the License.
             */
            setAddParticipant(elem.getAsString());
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("2")) {
        JsonElement elem = jsonObject.get("2");
        if (!elem.isJsonNull()) {

            /**
             * Licensed to the Apache Software Foundation (ASF) under one
             * or more contributor license agreements. See the NOTICE file
             * distributed with this work for additional information
             * regarding copyright ownership. The ASF licenses this file
             * to you under the Apache License, Version 2.0 (the
             * "License"); you may not use this file except in compliance
             * with the License. You may obtain a copy of the License at
             *
             * http://www.apache.org/licenses/LICENSE-2.0
             *
             * Unless required by applicable law or agreed to in writing,
             * software distributed under the License is distributed on an
             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
             * KIND, either express or implied. See the License for the
             * specific language governing permissions and limitations
             * under the License.
             */
            setRemoveParticipant(elem.getAsString());
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("3")) {
        JsonElement elem = jsonObject.get("3");
        if (!elem.isJsonNull()) {

            /**
             * Licensed to the Apache Software Foundation (ASF) under one
             * or more contributor license agreements. See the NOTICE file
             * distributed with this work for additional information
             * regarding copyright ownership. The ASF licenses this file
             * to you under the Apache License, Version 2.0 (the
             * "License"); you may not use this file except in compliance
             * with the License. You may obtain a copy of the License at
             *
             * http://www.apache.org/licenses/LICENSE-2.0
             *
             * Unless required by applicable law or agreed to in writing,
             * software distributed under the License is distributed on an
             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
             * KIND, either express or implied. See the License for the
             * specific language governing permissions and limitations
             * under the License.
             */
            MutateDocumentGsonImpl payload = new MutateDocumentGsonImpl();
            GsonUtil.extractJsonObject(payload, elem, gson, raw);
            setMutateDocument(payload);
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("4")) {
        JsonElement elem = jsonObject.get("4");
        if (!elem.isJsonNull()) {

            /**
             * Licensed to the Apache Software Foundation (ASF) under one
             * or more contributor license agreements. See the NOTICE file
             * distributed with this work for additional information
             * regarding copyright ownership. The ASF licenses this file
             * to you under the Apache License, Version 2.0 (the
             * "License"); you may not use this file except in compliance
             * with the License. You may obtain a copy of the License at
             *
             * http://www.apache.org/licenses/LICENSE-2.0
             *
             * Unless required by applicable law or agreed to in writing,
             * software distributed under the License is distributed on an
             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
             * KIND, either express or implied. See the License for the
             * specific language governing permissions and limitations
             * under the License.
             */
            setNoOp(elem.getAsBoolean());
        }
    }
}

From source file:org.waveprotocol.wave.federation.proto.ProtocolWaveletOperationProtoImpl.java

License:Apache License

@Override
public void fromGson(JsonElement json, Gson gson, RawStringData raw) throws GsonException {
    JsonObject jsonObject = json.getAsJsonObject();
    // NOTE: always check with has(...) as the json might not have all required
    // fields set; however these (obviously) will need to be set by other means
    // before accessing this object.
    invalidateAll();/*from   ww  w . j  a  v a 2 s  . c  o m*/

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("1")) {
        JsonElement elem = jsonObject.get("1");
        if (!elem.isJsonNull()) {
            setAddParticipant(elem.getAsString());
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("2")) {
        JsonElement elem = jsonObject.get("2");
        if (!elem.isJsonNull()) {
            setRemoveParticipant(elem.getAsString());
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("3")) {
        JsonElement elem = jsonObject.get("3");
        if (!elem.isJsonNull()) {
            {
                MutateDocumentProtoImpl payload = new MutateDocumentProtoImpl();
                GsonUtil.extractJsonObject(payload, elem, gson, raw);
                setMutateDocument(payload);
            }
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License. You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied. See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    if (jsonObject.has("4")) {
        JsonElement elem = jsonObject.get("4");
        if (!elem.isJsonNull()) {
            setNoOp(elem.getAsBoolean());
        }
    }
}

From source file:org.wso2.appfactory.integration.test.utils.rest.APIMIntegrationClient.java

License:Apache License

/**
*
* @param applicationKey applicationKey/*from   ww w .j  av  a  2  s. com*/
* @param userName userName
 * @return value of data element of the response
 * @throws Exception
*/
public boolean createApplication(String action, String applicationKey, String userName) throws Exception {
    // add header
    Map<String, String> entry = new HashMap<String, String>();
    entry.put(ACTION, action);
    entry.put(APPLICATION_KEY, applicationKey);
    entry.put(USER_NAME, userName);
    entry.put("SAML_TOKEN", samlRequest);

    HttpPost post = getHttpClient(entry, CREAT_APP_URL);
    HttpResponse response = (HttpResponse) httpclient.execute(post);

    /* process response */
    if (response.getResponseCode() == HttpStatus.SC_OK) {
        try {
            String responseString = response.getData();
            JsonParser jsonParser = new JsonParser();
            JsonElement jsonElement = jsonParser.parse(responseString);
            boolean addIssueResponse = jsonElement.getAsBoolean();
            if (addIssueResponse)
                return true;
        } catch (Exception e) {
            return false;
        }
    } else {
        throw new AFIntegrationTestException("" + response.getResponseCode() + response.getData());
    }
    return false;
}

From source file:org.wso2.appfactory.integration.test.utils.rest.APIMIntegrationClient.java

License:Apache License

/**
 *
 * @param applicationId applicationId//  w  ww  .ja v  a  2s . c om
 * @param userName userName
 * @throws Exception
 * @return value of data element of the response
 * @throws Exception
 */
public boolean keysExistsInAllStages(String action, String applicationId, String userName, String IsSync)
        throws Exception {
    // add header
    Map<String, String> entry = new HashMap<String, String>();
    entry.put(ACTION, action);
    entry.put(APPLICATION_KEY, applicationId);
    entry.put(USER, userName);
    entry.put(ISSYNC, IsSync);
    entry.put("SAML_TOKEN", samlRequest);
    HttpPost post = getHttpClient(entry, KEYEXISTS_URL);

    HttpResponse response = (HttpResponse) httpclient.execute(post);
    /* process response */
    if (response.getResponseCode() == HttpStatus.SC_OK) {
        try {
            String responseString = response.getData();
            JsonParser jsonParser = new JsonParser();
            JsonElement jsonElement = jsonParser.parse(responseString);
            boolean iskeysExistsInAllStages = jsonElement.getAsBoolean();
            if (iskeysExistsInAllStages) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    } else {
        throw new AFIntegrationTestException("" + response.getResponseCode() + response.getData());
    }
}

From source file:org.zoxweb.server.util.GSONUtil.java

License:Apache License

@SuppressWarnings("unchecked")
private static NVEntity fromJSON(JsonObject jo, Class<? extends NVEntity> clazz, Base64Type b64Type)
        throws AccessException, APIException {

    // check if the jo has class name setup
    // before creating the new instance
    JsonElement classType = jo.get(MetaToken.CLASS_TYPE.getName());

    if (classType != null) {
        if (!classType.isJsonNull()) {

            try {
                clazz = (Class<? extends NVEntity>) Class.forName(classType.getAsString());
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
                throw new APIException(e.getMessage(), Reason.NOT_FOUND);
            }//from   w w  w  .  jav  a 2s . co m
        }
    }

    NVEntity nve = null;

    try {
        try {
            nve = clazz.getDeclaredConstructor().newInstance();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            throw new APIException(e.getMessage(), Reason.NOT_FOUND);
        }
    } catch (InstantiationException | InvocationTargetException | NoSuchMethodException ie) {
        ie.printStackTrace();
        log.info("Error class:" + clazz);
        log.info("" + jo.toString());
        throw new APIException(ie.getMessage(), Reason.NOT_FOUND);
        //         if (ie instanceof InstantiationException)
        //            throw (InstantiationException)ie;
        //         else 
        //            throw new InstantiationException(ie.getMessage());

    } catch (SecurityException ie) {
        throw new AccessException(ie.getMessage(), Reason.ACCESS_DENIED);
    }

    if (jo.get(MetaToken.REFERENCE_ID.getName()) != null
            && !jo.get(MetaToken.REFERENCE_ID.getName()).isJsonNull()) {
        nve.setReferenceID(jo.get(MetaToken.REFERENCE_ID.getName()).getAsString());
    }

    NVConfigEntity mcEntity = (NVConfigEntity) nve.getNVConfig();

    List<NVConfig> nvconfigs = mcEntity.getAttributes();

    for (NVConfig nvc : nvconfigs) {
        Class<?> metaType = nvc.getMetaType();
        JsonElement je = jo.get(nvc.getName());

        if (je != null && !je.isJsonNull()) {
            NVBase<?> nvb = nve.lookup(nvc.getName());

            if (nvc.isArray()) {
                //if ( nvb instanceof NVBase<List<NVEntity>>)

                //if ( NVEntity.class.isAssignableFrom( metaType.getComponentType()))
                if (NVEntity.class.isAssignableFrom(nvc.getMetaTypeBase())) {
                    ArrayValues<NVEntity> tempArray = (ArrayValues<NVEntity>) nvb;
                    JsonArray jsonArray = je.getAsJsonArray();
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JsonObject jobj = jsonArray.get(i).getAsJsonObject();
                        //                     try
                        {
                            tempArray.add(
                                    fromJSON(jobj, (Class<? extends NVEntity>) nvc.getMetaTypeBase(), b64Type));
                        }
                        //                     catch (InstantiationException ie)
                        //                     {
                        //                        log.info("nvc:" + nvc.getName() + ":" + nvc.getMetaTypeBase());
                        //                        throw ie;
                        //                     }
                        //nvl.getValue().add( toNVPair( jobj));      
                    }
                }
                // enum must be checked first
                else if (metaType.getComponentType().isEnum()) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<List<Enum<?>>> nel = (NVBase<List<Enum<?>>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        String jobj = jsonArray.get(i).getAsString();
                        nel.getValue().add(SharedUtil.enumValue(metaType.getComponentType(), jobj));
                    }
                } else if (String[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    ArrayValues<NVPair> nvpm = (ArrayValues<NVPair>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        JsonObject jobj = jsonArray.get(i).getAsJsonObject();
                        nvpm.add(toNVPair(jobj));
                    }
                } else if (Long[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<Long>> nval = (NVBase<ArrayList<Long>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add(jsonArray.get(i).getAsLong());
                    }
                } else if (byte[].class.equals(metaType)) {
                    String byteArray64 = je.getAsString();

                    if (byteArray64 != null) {
                        nve.setValue(nvc, SharedBase64.decode(b64Type, byteArray64.getBytes()));
                    }
                } else if (Integer[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<Integer>> nval = (NVBase<ArrayList<Integer>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add((int) jsonArray.get(i).getAsLong());
                    }
                } else if (Float[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<Float>> nval = (NVBase<ArrayList<Float>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add((float) jsonArray.get(i).getAsDouble());
                    }
                } else if (Double[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<Double>> nval = (NVBase<ArrayList<Double>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add(jsonArray.get(i).getAsDouble());
                    }
                } else if (Date[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<Long>> nval = (NVBase<ArrayList<Long>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        JsonPrimitive jp = (JsonPrimitive) jsonArray.get(i);
                        long tempDate = 0;

                        if (jp.isString() && nvc.getValueFilter() != null) {
                            tempDate = (Long) nvc.getValueFilter().validate(jp.getAsString());
                        } else {
                            tempDate = jp.getAsLong();
                        }

                        nval.getValue().add(tempDate);
                    }
                } else if (BigDecimal[].class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVBase<ArrayList<BigDecimal>> nval = (NVBase<ArrayList<BigDecimal>>) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add(jsonArray.get(i).getAsBigDecimal());
                    }
                }

            } else {
                // not array
                if (nvc instanceof NVConfigEntity) {
                    if (!(je instanceof JsonNull)) {
                        ((NVBase<NVEntity>) nvb).setValue(fromJSON(je.getAsJsonObject(),
                                (Class<? extends NVEntity>) nvc.getMetaType(), b64Type));
                    }
                } else if (NVGenericMap.class.equals(metaType)) {

                    if (!(je instanceof JsonNull)) {
                        NVGenericMap nvgm = fromJSONGenericMap(je.getAsJsonObject(), null, b64Type);
                        ((NVGenericMap) nve.lookup(nvc)).add(nvgm.values(), true);

                    }

                } else if (NVStringList.class.equals(metaType)) {
                    JsonArray jsonArray = je.getAsJsonArray();
                    NVStringList nval = (NVStringList) nvb;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        nval.getValue().add(jsonArray.get(i).getAsString());
                    }
                } else if (nvc.isEnum()) {
                    if (!(je instanceof JsonNull)) {
                        //                     if (metaType.isAssignableFrom( DynamicEnumMap.class))
                        //                     {
                        //                        
                        //                        ((NVDynamicEnum)nvb).setValue(je.getAsString());
                        //                     }
                        //                     else
                        {
                            ((NVBase<Enum<?>>) nvb).setValue(SharedUtil.enumValue(metaType, je.getAsString()));
                        }
                    }
                } else if (String.class.equals(metaType)) {
                    if (!(je instanceof JsonNull)) {
                        ((NVPair) nvb).setValue(je.getAsString());
                    }
                } else if (Long.class.equals(metaType)) {
                    ((NVBase<Long>) nvb).setValue(je.getAsLong());
                } else if (Boolean.class.equals(metaType)) {
                    ((NVBase<Boolean>) nvb).setValue(je.getAsBoolean());
                } else if (Integer.class.equals(metaType)) {
                    ((NVBase<Integer>) nvb).setValue((int) je.getAsLong());
                } else if (Float.class.equals(metaType)) {
                    ((NVBase<Float>) nvb).setValue((float) je.getAsDouble());
                } else if (Double.class.equals(metaType)) {
                    ((NVBase<Double>) nvb).setValue(je.getAsDouble());
                } else if (Date.class.equals(metaType)) {
                    JsonPrimitive jp = (JsonPrimitive) je;

                    if (jp.isString()) {
                        if (nvc.getValueFilter() != null)
                            ((NVBase<Long>) nvb)
                                    .setValue((Long) nvc.getValueFilter().validate(jp.getAsString()));
                        else
                            ((NVBase<Long>) nvb).setValue(TimestampFilter.SINGLETON.validate(jp.getAsString()));
                    }

                    else {
                        ((NVBase<Long>) nvb).setValue(jp.getAsLong());
                    }
                } else if (BigDecimal.class.equals(metaType)) {
                    ((NVBase<BigDecimal>) nvb).setValue(je.getAsBigDecimal());
                }

            }
        }

    }

    if (nve instanceof SubjectID) {
        ((SubjectID<?>) nve).getSubjectID();
    }
    return nve;
}

From source file:vellum.json.JsonObjectDelegate.java

License:Apache License

public boolean getBoolean(String key, boolean defaultValue) {
    JsonElement element = get(key);
    if (element == null) {
        return defaultValue;
    }//from   w w  w.  j  a  v a 2s .  co  m
    return element.getAsBoolean();
}

From source file:vellum.jx.JMaps.java

License:Apache License

public static Object parsePrimitive(JsonElement element) {
    String string = element.toString();
    if (string.equals("true")) {
        return element.getAsBoolean();
    } else if (string.equals("false")) {
        return element.getAsBoolean();
    } else if (string.startsWith("\"")) {
        return element.getAsString();
    } else if (string.contains(".")) {
        return element.getAsDouble();
    } else if (string.matches("[0-9]*")) {
        return element.getAsLong();
    }/* w ww .  ja va2  s .co  m*/
    return element.getAsString();
}