Example usage for com.fasterxml.jackson.databind ObjectMapper configure

List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper configure.

Prototype

public ObjectMapper configure(JsonGenerator.Feature f, boolean state) 

Source Link

Document

Method for changing state of an on/off JsonGenerator feature for JsonFactory instance this object mapper uses.

Usage

From source file:org.wso2.emm.agent.services.operation.OperationManager.java

/**
 * Monitor currently enforced policy for compliance.
 *
 * @param operation - Operation object./*from  w w  w.j a  v a  2 s  . co m*/
 */
public void monitorPolicy(org.wso2.emm.agent.beans.Operation operation) throws AndroidAgentException {
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "monitorPolicy started.");
    }
    String payload = Preference.getString(context, Constants.PreferenceFlag.APPLIED_POLICY);
    PolicyOperationsMapper operationsMapper = new PolicyOperationsMapper();
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    PolicyComplianceChecker policyChecker = new PolicyComplianceChecker(context);
    ArrayList<ComplianceFeature> result = new ArrayList<>();

    try {
        if (payload != null) {
            List<org.wso2.emm.agent.beans.Operation> operations = mapper.readValue(payload,
                    mapper.getTypeFactory().constructCollectionType(List.class,
                            org.wso2.emm.agent.beans.Operation.class));
            for (org.wso2.emm.agent.beans.Operation op : operations) {
                op = operationsMapper.getOperation(op);
                result.add(policyChecker.checkPolicyState(op));
            }
            operation.setStatus(resources.getString(R.string.operation_value_completed));
            operation.setPayLoad(mapper.writeValueAsString(result));
            resultBuilder.build(operation);
        }
    } catch (IOException e) {
        operation.setStatus(resources.getString(R.string.operation_value_error));
        operation.setOperationResponse("Error in parsing policy monitor payload stream.");
        resultBuilder.build(operation);
        throw new AndroidAgentException("Error occurred while parsing stream.", e);
    }
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "monitorPolicy completed.");
    }
}

From source file:it.sayservice.platform.smartplanner.otp.OTPHandler.java

public List<TransitStops> getRouteData(String agencyId, String routeId) throws Exception {
    List<TransitStops> result = new ArrayList<TransitStops>();

    try {//w  w w .j  a v  a 2 s. c o m
        String routeIdOTP = agencyId + ":" + routeId;
        String res = HTTPConnector.doGet(otpURL + Constants.OP_ROUTES + "/" + routeIdOTP + "/stops", "",
                MediaType.APPLICATION_JSON, null);
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        // new version.
        List routeStopsList = mapper.readValue(res, List.class);

        List<String> stopsId = new ArrayList<String>();
        for (Object rstopObject : routeStopsList) {
            Map stopObjectMap = (Map) rstopObject;
            String[] ids = stopObjectMap.get("id").toString().split(":");
            stopsId.add(ids[1]);

        }

        TransitStops trip = new TransitStops();
        trip.setAgency(agencyId);
        trip.setId(routeId);
        trip.getStopsId().addAll(stopsId);

        result.add(trip);
        // }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:it.sayservice.platform.smartplanner.otp.OTPHandler.java

public List<Route> getRoutes(String router) {
    List<Route> result = new ArrayList<Route>();

    try {/*from w ww.  j  a  v a 2s  .  c  om*/
        String res = HTTPConnector.doGet(otpURL + Constants.OP_ROUTES, "", null, MediaType.APPLICATION_JSON);

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        ArrayList list = mapper.readValue(res, ArrayList.class);

        for (Object o : list) {
            Map<String, Object> tmpMap = mapper.convertValue(o, Map.class);
            // Route route = mapper.convertValue(tmpMap.get("RouteType"),
            // Route.class);
            // new version.
            String[] ids = tmpMap.get("id").toString().split(":");
            String agencyId = ids[0];
            String routeId = ids[1];

            Route route = new Route();
            Id id = new Id();
            id.setAgency(agencyId);
            id.setId(routeId);
            route.setId(id);
            if (tmpMap.containsKey("longName"))
                route.setRouteLongName(tmpMap.get("longName").toString());
            if (tmpMap.containsKey("shortName"))
                route.setRouteShortName(tmpMap.get("shortName").toString());

            result.add(route);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:TaxSvc.TaxSvc.java

public GetTaxResult GetTax(GetTaxRequest req) {

    //Create URL/* w ww.ja  v  a 2  s  .com*/
    String taxget = svcURL + "/1.0/tax/get";
    URL url;

    HttpURLConnection conn;
    try {
        //Connect to URL with authorization header, request content.
        url = new URL(taxget);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setAllowUserInteraction(false);

        String encoded = "Basic " + new String(Base64.encodeBase64((accountNum + ":" + license).getBytes())); //Create auth content
        conn.setRequestProperty("Authorization", encoded); //Add authorization header
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL); //Tells the serializer to only include those parameters that are not null
        String content = mapper.writeValueAsString(req);
        //System.out.println(content);   //Uncomment to see the content of the request object
        conn.setRequestProperty("Content-Length", Integer.toString(content.length()));

        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        wr.writeBytes(content);
        wr.flush();
        wr.close();

        conn.disconnect();

        if (conn.getResponseCode() != 200) //If we didn't get a success back, print out the error.
        {
            GetTaxResult res = mapper.readValue(conn.getErrorStream(), GetTaxResult.class); //Deserializes the response
            return res;
        }

        else //Otherwise, print out the total tax calculated
        {
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            GetTaxResult res = mapper.readValue(conn.getInputStream(), GetTaxResult.class); //Deserializes the response
            return res;
        }

    } catch (IOException e) {
        e.printStackTrace();
        return null;

    }
}

From source file:synapticloop.scaleway.api.ScalewayApiClient.java

private ObjectMapper initializeObjectMapperJson() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return mapper;
}

From source file:org.openspaces.rest.space.SpaceAPIController.java

@ApiMethod(path = "{type}/_introduce_type", verb = ApiVerb.PUT, description = "Introduces the specified type to the space with the provided description in the body", consumes = {
        MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE }

)
@RequestMapping(value = "/{type}/_introduce_type", method = RequestMethod.PUT, consumes = {
        MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> introduceTypeAdvanced(
        @PathVariable @ApiPathParam(name = "type", description = TYPE_DESCRIPTION) String type,
        @RequestBody(required = false) @ApiBodyObject String requestBody) {
    if (logger.isLoggable(Level.FINE))
        logger.fine("introducing type: " + type);

    if (requestBody == null) {
        throw new RestException("Request body cannot be empty");
    }/*w  w w  . j  a  v a 2  s.c om*/

    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        JsonNode actualObj = mapper.readTree(requestBody);

        //check that the json does not have any "unknown" elements
        Iterator<String> iterator = actualObj.fieldNames();
        while (iterator.hasNext()) {
            String fieldName = iterator.next();
            if (!ControllerUtils.allowedFields.contains(fieldName)) {
                throw new RestException("Unknown field: " + fieldName);
            }
        }

        SpaceTypeDescriptorBuilder spaceTypeDescriptor = new SpaceTypeDescriptorBuilder(type);

        JsonNode idProperty = actualObj.get("idProperty");
        if (idProperty == null) {
            throw new RestException("idProperty must be provided");
        } else {
            if (!idProperty.isObject()) {
                throw new RestException("idProperty value must be object");
            }
            Iterator<String> idPropertyIterator = idProperty.fieldNames();
            while (idPropertyIterator.hasNext()) {
                String fieldName = idPropertyIterator.next();
                if (!fieldName.equals("propertyName") && !fieldName.equals("autoGenerated")
                        && !fieldName.equals("indexType")) {
                    throw new RestException("Unknown idProperty field: " + fieldName);
                }
            }
            String propertyName = getString(idProperty.get("propertyName"));
            if (propertyName != null && !idProperty.get("propertyName").isTextual()) {
                throw new RestException("idProperty.propertyName must be textual");
            }
            Boolean autoGenerated = getBoolean(idProperty.get("autoGenerated"));
            if (autoGenerated != null && !idProperty.get("autoGenerated").isBoolean()) {
                throw new RestException("idProperty.autoGenerated must be boolean");
            }
            String indexType = getString(idProperty.get("indexType"));
            if (indexType != null && !idProperty.get("indexType").isTextual()) {
                throw new RestException("idProperty.indexType must be textual");
            }

            if (propertyName == null) {
                throw new RestException("idProperty.propertyName must be provided");
            } else if (autoGenerated == null && indexType == null) {
                spaceTypeDescriptor.idProperty(propertyName);
            } else if (autoGenerated != null && indexType == null) {
                spaceTypeDescriptor.idProperty(propertyName, autoGenerated);
            } else if (autoGenerated != null && indexType != null) {
                SpaceIndexType spaceIndexType;
                try {
                    spaceIndexType = SpaceIndexType.valueOf(indexType);
                } catch (IllegalArgumentException e) {
                    throw new RestException("Illegal idProperty.indexType: " + e.getMessage());
                }
                spaceTypeDescriptor.idProperty(propertyName, autoGenerated, spaceIndexType);
            } else {
                throw new RestException("idProperty.indexType cannot be used without idProperty.autoGenerated");
            }
        }

        JsonNode routingProperty = actualObj.get("routingProperty");
        if (routingProperty != null) {
            if (!routingProperty.isObject()) {
                throw new RestException("routingProperty value must be object");
            }
            Iterator<String> routingPropertyIterator = routingProperty.fieldNames();
            while (routingPropertyIterator.hasNext()) {
                String fieldName = routingPropertyIterator.next();
                if (!fieldName.equals("propertyName") && !fieldName.equals("indexType")) {
                    throw new RestException("Unknown routingProperty field: " + fieldName);
                }
            }
            String propertyName = getString(routingProperty.get("propertyName"));
            if (propertyName != null && !routingProperty.get("propertyName").isTextual()) {
                throw new RestException("routingProperty.propertyName must be textual");
            }
            String indexType = getString(routingProperty.get("indexType"));
            if (indexType != null && !routingProperty.get("indexType").isTextual()) {
                throw new RestException("routingProperty.indexType must be textual");
            }

            if (propertyName == null) {
                throw new RestException("routingProperty.propertyName must be provided");
            } else if (indexType == null) {
                spaceTypeDescriptor.routingProperty(propertyName);
            } else { //(indexType != null)
                SpaceIndexType spaceIndexType;
                try {
                    spaceIndexType = SpaceIndexType.valueOf(indexType);
                } catch (IllegalArgumentException e) {
                    throw new RestException("Illegal routingProperty.indexType: " + e.getMessage());
                }
                spaceTypeDescriptor.routingProperty(propertyName, spaceIndexType);
            }
        }

        JsonNode compoundIndex = actualObj.get("compoundIndex");
        if (compoundIndex != null) {
            Iterator<String> compoundIndexIterator = compoundIndex.fieldNames();
            while (compoundIndexIterator.hasNext()) {
                String fieldName = compoundIndexIterator.next();
                if (!fieldName.equals("paths") && !fieldName.equals("unique")) {
                    throw new RestException("Unknown compoundIndex field: " + fieldName);
                }
            }
            JsonNode paths = compoundIndex.get("paths");
            if (paths != null && !paths.isArray()) {
                throw new RestException("compoundIndex.paths must be array of strings");
            }
            Boolean unique = getBoolean(compoundIndex.get("unique"));
            if (unique != null && !compoundIndex.get("unique").isBoolean()) {
                throw new RestException("compoundIndex.unique must be boolean");
            }

            if (paths == null) {
                throw new RestException("compoundIndex.paths must be provided");
            } else {
                if (paths.size() == 0) {
                    throw new RestException("compoundIndex.paths cannot be empty");
                }
                String[] pathsArr = new String[paths.size()];
                for (int i = 0; i < paths.size(); i++) {
                    pathsArr[i] = paths.get(i).asText();
                }
                if (unique == null) {
                    spaceTypeDescriptor.addCompoundIndex(pathsArr);
                } else {
                    spaceTypeDescriptor.addCompoundIndex(pathsArr, unique);
                }
            }
        }

        String fifoSupport = getString(actualObj.get("fifoSupport"));
        if (fifoSupport != null) {
            if (!actualObj.get("fifoSupport").isTextual()) {
                throw new RestException("fifoSupport must be textual");
            }
            FifoSupport fifoSupportEnum;
            try {
                fifoSupportEnum = FifoSupport.valueOf(fifoSupport);
            } catch (IllegalArgumentException e) {
                throw new RestException("Illegal fifoSupport: " + e.getMessage());
            }
            spaceTypeDescriptor.fifoSupport(fifoSupportEnum);
        }

        Boolean blobStoreEnabled = getBoolean(actualObj.get("blobStoreEnabled"));
        if (blobStoreEnabled != null) {
            if (!actualObj.get("blobStoreEnabled").isBoolean()) {
                throw new RestException("blobStoreEnabled must be boolean");
            }
            spaceTypeDescriptor.setBlobstoreEnabled(blobStoreEnabled);
        }

        String documentStorageType = getString(actualObj.get("storageType"));
        if (documentStorageType != null) {
            if (!actualObj.get("storageType").isTextual()) {
                throw new RestException("storageType must be textual");
            }
            StorageType storageType;
            try {
                storageType = StorageType.valueOf(documentStorageType);
            } catch (IllegalArgumentException e) {
                throw new RestException("Illegal storageType: " + e.getMessage());
            }
            spaceTypeDescriptor.storageType(storageType);
        }

        Boolean supportsOptimisticLocking = getBoolean(actualObj.get("supportsOptimisticLocking"));
        if (supportsOptimisticLocking != null) {
            if (!actualObj.get("supportsOptimisticLocking").isBoolean()) {
                throw new RestException("supportsOptimisticLocking must be boolean");
            }
            spaceTypeDescriptor.supportsOptimisticLocking(supportsOptimisticLocking);
        }

        Boolean supportsDynamicProperties = getBoolean(actualObj.get("supportsDynamicProperties"));
        if (supportsDynamicProperties != null) {
            if (!actualObj.get("supportsDynamicProperties").isBoolean()) {
                throw new RestException("supportsDynamicProperties must be boolean");
            }
            spaceTypeDescriptor.supportsDynamicProperties(supportsDynamicProperties);
        } else {
            spaceTypeDescriptor.supportsDynamicProperties(true);
        }

        HashSet<String> fixedPropertiesNames = new HashSet<String>();
        JsonNode fixedProperties = actualObj.get("fixedProperties");
        if (fixedProperties != null) {
            for (int i = 0; i < fixedProperties.size(); i++) {
                JsonNode fixedProperty = fixedProperties.get(i);
                Iterator<String> fixedPropertyIterator = fixedProperty.fieldNames();
                while (fixedPropertyIterator.hasNext()) {
                    String fieldName = fixedPropertyIterator.next();
                    if (!fieldName.equals("propertyName") && !fieldName.equals("propertyType")
                            && !fieldName.equals("documentSupport") && !fieldName.equals("storageType")
                            && !fieldName.equals("indexType") && !fieldName.equals("uniqueIndex")) {
                        throw new RestException(
                                "Unknown field: " + fieldName + " of FixedProperty at index [" + i + "]");
                    }
                }

                String propertyName = getString(fixedProperty.get("propertyName"));
                if (propertyName != null && !fixedProperty.get("propertyName").isTextual()) {
                    throw new RestException(
                            "propertyName of FixedProperty at index [" + i + "] must be textual");
                }
                String propertyType = getString(fixedProperty.get("propertyType"));
                if (propertyType != null && !fixedProperty.get("propertyType").isTextual()) {
                    throw new RestException(
                            "propertyType of FixedProperty at index [" + i + "] must be textual");
                }
                String documentSupport = getString(fixedProperty.get("documentSupport"));
                if (documentSupport != null && !fixedProperty.get("documentSupport").isTextual()) {
                    throw new RestException(
                            "documentSupport of FixedProperty at index [" + i + "] must be textual");
                }
                String propertyStorageType = getString(fixedProperty.get("storageType"));
                if (propertyStorageType != null && !fixedProperty.get("storageType").isTextual()) {
                    throw new RestException(
                            "storageType of FixedProperty at index [" + i + "] must be textual");
                }

                //addPropertyIndex
                String indexType = getString(fixedProperty.get("indexType"));
                if (indexType != null && !(fixedProperty.get("indexType").isTextual())) {
                    throw new RestException("indexType of FixedProperty at index [" + i + "] must be textual");
                }
                Boolean uniqueIndex = getBoolean(fixedProperty.get("uniqueIndex"));
                if (indexType == null && uniqueIndex != null) {
                    throw new RestException(
                            "uniqueIndex cannot be used without indexType field in FixedProperty at index [" + i
                                    + "]");
                }
                if (uniqueIndex != null && !fixedProperty.get("uniqueIndex").isBoolean()) {
                    throw new RestException(
                            "uniqueIndex of FixedProperty at index [" + i + "] must be boolean");
                }
                if (indexType != null) {
                    SpaceIndexType spaceIndexType;
                    try {
                        spaceIndexType = SpaceIndexType.valueOf(indexType);
                    } catch (IllegalArgumentException e) {
                        throw new RestException("Illegal fixedProperty.indexType: " + e.getMessage());
                    }
                    if (uniqueIndex == null) {
                        spaceTypeDescriptor.addPropertyIndex(propertyName, spaceIndexType);
                    } else {
                        spaceTypeDescriptor.addPropertyIndex(propertyName, spaceIndexType, uniqueIndex);
                    }
                }

                if (propertyName == null) {
                    throw new RestException("Missing propertyName in FixedProperty at index [" + i + "]");
                }
                if (propertyType == null) {
                    throw new RestException("Missing propertyType in FixedProperty at index [" + i + "]");
                }
                if (fixedPropertiesNames.add(propertyName) == false) {
                    throw new KeyAlreadyExistException(propertyName);
                }
                Class propertyValueClass = ControllerUtils.javaPrimitives.get(propertyType);

                if (documentSupport == null && propertyStorageType == null) {
                    if (propertyValueClass != null) {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyValueClass);
                    } else {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyType);
                    }
                } else if (documentSupport == null && propertyStorageType != null) {
                    throw new RestException(
                            "Cannot apply storageType of FixedProperty without specifying documentSupport");
                } else if (documentSupport != null && propertyStorageType == null) {
                    SpaceDocumentSupport spaceDocumentSupport;
                    try {
                        spaceDocumentSupport = SpaceDocumentSupport.valueOf(documentSupport);
                    } catch (IllegalArgumentException e) {
                        throw new RestException("Illegal fixedProperty.documentSupport: " + e.getMessage());
                    }

                    if (propertyValueClass != null) {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyValueClass,
                                spaceDocumentSupport);
                    } else {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyType, spaceDocumentSupport);
                    }
                } else {
                    SpaceDocumentSupport spaceDocumentSupport;
                    try {
                        spaceDocumentSupport = SpaceDocumentSupport.valueOf(documentSupport);
                    } catch (IllegalArgumentException e) {
                        throw new RestException("Illegal fixedProperty.documentSupport: " + e.getMessage());
                    }
                    StorageType storageType;
                    try {
                        storageType = StorageType.valueOf(propertyStorageType);
                    } catch (IllegalArgumentException e) {
                        throw new RestException("Illegal fixedProperty.storageType: " + e.getMessage());
                    }
                    if (propertyValueClass != null) {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyValueClass,
                                spaceDocumentSupport, storageType);
                    } else {
                        spaceTypeDescriptor.addFixedProperty(propertyName, propertyType, spaceDocumentSupport,
                                storageType);
                    }
                }

            }
        }

        GigaSpace gigaSpace = ControllerUtils.xapCache.get();
        SpaceTypeDescriptor typeDescriptor = gigaSpace.getTypeManager().getTypeDescriptor(type);
        if (typeDescriptor != null) {
            throw new TypeAlreadyRegisteredException(type);
        }

        gigaSpace.getTypeManager().registerTypeDescriptor(spaceTypeDescriptor.create());

        HashMap<String, Object> result = new HashMap<String, Object>();
        result.put("status", "success");
        return result;
    } catch (IOException e) {
        throw new RestException(e.getMessage());

    } catch (KeyAlreadyExistException e) {
        throw new RestException(e.getMessage());
    }
}

From source file:TaxSvc.TaxSvc.java

public CancelTaxResult CancelTax(CancelTaxRequest req) {

    //Create URL/*from  w  ww .j  av a 2 s  . c  om*/
    String taxget = svcURL + "/1.0/tax/cancel";
    URL url;
    HttpURLConnection conn;
    try {
        //Connect to URL with authorization header, request content.
        url = new URL(taxget);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setAllowUserInteraction(false);

        String encoded = "Basic " + new String(Base64.encodeBase64((accountNum + ":" + license).getBytes())); //Create auth content
        conn.setRequestProperty("Authorization", encoded); //Add authorization header
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL); //Tells the serializer to only include those parameters that are not null
        String content = mapper.writeValueAsString(req);
        //System.out.println(content);         //Uncomment to see the content of the request object
        conn.setRequestProperty("Content-Length", Integer.toString(content.length()));

        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        wr.writeBytes(content);
        wr.flush();
        wr.close();

        conn.disconnect();

        if (conn.getResponseCode() != 200) //Note: tax/cancel will return a 200 response even if the document could not be cancelled. Special attention needs to be paid to the ResultCode.
        { //If we got a more serious error, print out the error message.
            CancelTaxResult res = mapper.readValue(conn.getErrorStream(), CancelTaxResult.class); //Deserialize response
            return res;
        } else {
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            CancelTaxResponse res = mapper.readValue(conn.getInputStream(), CancelTaxResponse.class); //Deserialize response
            return res.CancelTaxResult;
        }

    } catch (IOException e) {
        e.printStackTrace();
        return null;

    }
}

From source file:net.sf.jasperreports.engine.export.JsonMetadataExporter.java

public void validateSchema(String jsonSchema) throws JRException {
    ObjectMapper mapper = new ObjectMapper();

    // relax the JSON rules
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);

    try {//from   ww w .j  a  v  a 2 s  . com
        JsonNode root = mapper.readTree(jsonSchema);
        if (root.isObject()) {
            pathToValueNode = new HashMap<String, SchemaNode>();
            pathToObjectNode = new HashMap<String, SchemaNode>();

            previousPath = null;

            if (!isValid((ObjectNode) root, JSON_SCHEMA_ROOT_NAME, "", null)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_INVALID_JSON_OBJECT_SEMANTIC, (Object[]) null);
            }
        } else {
            throw new JRException(EXCEPTION_MESSAGE_KEY_INVALID_JSON_OBJECT_ARRAY_FOUND, (Object[]) null);
        }

    } catch (IOException e) {
        throw new JRException(EXCEPTION_MESSAGE_KEY_INVALID_JSON_OBJECT, (Object[]) null);
    }
}

From source file:org.wso2.iot.agent.services.operation.OperationManager.java

/**
 * Monitor currently enforced policy for compliance.
 *
 * @param operation - Operation object.//w w  w  .  java 2 s  .c o  m
 */
public void monitorPolicy(org.wso2.iot.agent.beans.Operation operation) throws AndroidAgentException {
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "monitorPolicy started.");
    }
    String payload = Preference.getString(context, Constants.PreferenceFlag.APPLIED_POLICY);
    PolicyOperationsMapper operationsMapper = new PolicyOperationsMapper();
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    PolicyComplianceChecker policyChecker = new PolicyComplianceChecker(context);
    ArrayList<ComplianceFeature> result = new ArrayList<>();

    try {
        if (payload != null) {
            List<org.wso2.iot.agent.beans.Operation> operations = mapper.readValue(payload,
                    mapper.getTypeFactory().constructCollectionType(List.class,
                            org.wso2.iot.agent.beans.Operation.class));
            for (org.wso2.iot.agent.beans.Operation op : operations) {
                op = operationsMapper.getOperation(op);
                result.add(policyChecker.checkPolicyState(op));
            }
            operation.setStatus(resources.getString(R.string.operation_value_completed));
            operation.setPayLoad(mapper.writeValueAsString(result));
            resultBuilder.build(operation);
        }
    } catch (IOException e) {
        operation.setStatus(resources.getString(R.string.operation_value_error));
        operation.setOperationResponse("Error in parsing policy monitor payload stream.");
        resultBuilder.build(operation);
        throw new AndroidAgentException("Error occurred while parsing stream.", e);
    }
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "monitorPolicy completed.");
    }
}

From source file:io.fabric8.core.jmx.FabricManager.java

private ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    return mapper;
}