org.codehaus.jackson.JsonParseException Java Examples

The following examples show how to use org.codehaus.jackson.JsonParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONUtil.java    From kardio with Apache License 2.0 6 votes vote down vote up
/**
 * Function to validate the json string
 * @param json
 * @return
 */
public static boolean isJSONValid(String json) {
	 boolean valid = false;
	   try {
	      final JsonParser parser = new ObjectMapper().getJsonFactory()
	            .createJsonParser(json);
	      while (parser.nextToken() != null) {
	      }
	      valid = true;
	   } catch (JsonParseException jpe) {
		   logger.error("Invalid JSON String JsonParseException");
	   } catch (IOException ioe) {
		   logger.error("Invalid JSON String IOException");
	   }

	   return valid;
}
 
Example #2
Source File: SiteToSiteRestApiClient.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private TransactionResultEntity readResponse(final InputStream inputStream) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();

    StreamUtils.copy(inputStream, bos);
    String responseMessage = null;

    try {
        responseMessage = new String(bos.toByteArray(), "UTF-8");
        logger.debug("readResponse responseMessage={}", responseMessage);

        final ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(responseMessage, TransactionResultEntity.class);
    } catch (JsonParseException | JsonMappingException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to parse JSON.", e);
        }

        final TransactionResultEntity entity = new TransactionResultEntity();
        entity.setResponseCode(ResponseCode.ABORT.getCode());
        entity.setMessage(responseMessage);
        return entity;
    }
}
 
Example #3
Source File: JsonSerDeser.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Convert from a JSON file
 * @param resource input file
 * @return the parsed JSON
 * @throws IOException IO problems
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
public synchronized T fromResource(String resource)
    throws IOException, JsonParseException, JsonMappingException {
  InputStream resStream = null;
  try {
    resStream = this.getClass().getResourceAsStream(resource);
    if (resStream == null) {
      throw new FileNotFoundException(resource);
    }
    return mapper.readValue(resStream, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json resource {}: {}", resource, e);
    throw e;
  } finally {
    IOUtils.closeStream(resStream);
  }
}
 
Example #4
Source File: JsonSerdeUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Object parseValue(@Nonnull final JsonParser p)
        throws JsonParseException, IOException {
    final JsonToken t = p.getCurrentToken();
    switch (t) {
        case VALUE_FALSE:
            return Boolean.FALSE;
        case VALUE_TRUE:
            return Boolean.TRUE;
        case VALUE_NULL:
            return null;
        case VALUE_STRING:
            return p.getText();
        case VALUE_NUMBER_FLOAT:
            return p.getDoubleValue();
        case VALUE_NUMBER_INT:
            return p.getIntValue();
        default:
            throw new IOException("Unexpected token: " + t);
    }
}
 
Example #5
Source File: HiveJsonStructReader.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private static void skipValue(JsonParser parser) throws JsonParseException, IOException {
    int array = 0;
    int object = 0;
    do {
        JsonToken currentToken = parser.getCurrentToken();
        if (currentToken == JsonToken.START_ARRAY) {
            array++;
        }
        if (currentToken == JsonToken.END_ARRAY) {
            array--;
        }
        if (currentToken == JsonToken.START_OBJECT) {
            object++;
        }
        if (currentToken == JsonToken.END_OBJECT) {
            object--;
        }

        parser.nextToken();

    } while (array > 0 || object > 0);
}
 
Example #6
Source File: JsonUtil.java    From hbase-secondary-index with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public Set<String> evaluateDistinctArray(String jsonString,
		String pathString) throws JsonParseException, JsonMappingException,
		IOException {
	Set<String> set = new HashSet<String>();
	if (jsonString == null || jsonString == "" || pathString == null
			|| pathString == "") {
		return null;
	}

	List result = MAPPER.readValue(jsonString, new TypeReference<List>() {
	});
	for (Object o : result) {
		if (o instanceof LinkedHashMap) {
			LinkedHashMap m = (LinkedHashMap) o;
			set.add(m.get(pathString).toString());
		} else if (o instanceof String) {
			String str = (String) o;
			String[] arr = str.split(Const.ROWKEY_DEFAULT_SEPARATOR, -1);
			for (String s : arr) {
				set.add(s);
			}
		}
	}
	return set;
}
 
Example #7
Source File: GeneralMesseageConsumer.java    From laser with Apache License 2.0 6 votes vote down vote up
private boolean setUserProfile(String uuid, Vector profile)
		throws JsonParseException, JsonMappingException, IOException {
	try {
		Object res = couchbaseClient.get(uuid);
		if (null == res) {
			return false;
		}

		String jsonValue = res.toString();
		UserProfile userProfile = UserProfile.createUserProfile(jsonValue);
		userProfile.setUserFeature(profile, mapper, true);
	} catch (RuntimeException e) {
		return false;
	}
	return true;
}
 
Example #8
Source File: BasicClient.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public Response getHomeResource(Entity home) throws URISyntaxException, MessageProcessingException, IOException {

    URL url = URLBuilder.create(restClient.getBaseURL()).addPath(PathConstants.HOME).build();

    Response response = restClient.getRequest(url);
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        try {
            JsonNode element = mapper.readValue(response.readEntity(String.class), JsonNode.class);
            Map<String, List<Link>> links = mapper.readValue(element,
                    new TypeReference<Map<String, List<BasicLink>>>() {
                    });
            home.getData().putAll(links);
        } catch (JsonParseException e) {
            // invalid Json, or non-Json response?
            ResponseBuilder builder = Response.fromResponse(response);
            builder.status(Response.Status.INTERNAL_SERVER_ERROR);
            return builder.build();
        }
    }
    return response;
}
 
Example #9
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration)
    throws IOException, JsonParseException, JsonMappingException {
  String content = configuration.get("schema.path.mapping");
  Map<String, String> schemaPathMapping =
      new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE);
  LOGGER.info("Schema Path Mapping: {}", schemaPathMapping);

  String sourceName = null;
  for (String path : schemaPathMapping.keySet()) {
    if (fileSplit.getPath().toString().indexOf(path) > -1) {
      sourceName = schemaPathMapping.get(path);
      break;
    }
  }
  return sourceName;
}
 
Example #10
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration)
    throws IOException, JsonParseException, JsonMappingException {
  String content = configuration.get("schema.path.mapping");
  Map<String, String> schemaPathMapping =
      new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE);
  LOGGER.info("Schema Path Mapping: {}", schemaPathMapping);

  String sourceName = null;
  for (String path : schemaPathMapping.keySet()) {
    if (fileSplit.getPath().toString().indexOf(path) > -1) {
      sourceName = schemaPathMapping.get(path);
      break;
    }
  }
  return sourceName;
}
 
Example #11
Source File: AbstractSiteToSiteReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
public JsonRecordReader(final InputStream in, RecordSchema recordSchema) throws IOException, MalformedRecordException {
    this.recordSchema = recordSchema;
    try {
        jsonParser = new JsonFactory().createJsonParser(in);
        jsonParser.setCodec(new ObjectMapper());
        JsonToken token = jsonParser.nextToken();
        if (token == JsonToken.START_ARRAY) {
            array = true;
            token = jsonParser.nextToken();
        } else {
            array = false;
        }
        if (token == JsonToken.START_OBJECT) {
            firstJsonNode = jsonParser.readValueAsTree();
        } else {
            firstJsonNode = null;
        }
    } catch (final JsonParseException e) {
        throw new MalformedRecordException("Could not parse data as JSON", e);
    }
}
 
Example #12
Source File: JsonDataValidator.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean isValidJSON(String json) {
    boolean valid = false;
    try {
        final JsonParser parser = new ObjectMapper().getJsonFactory()
                .createJsonParser(json);
        while (parser.nextToken() != null) {
            String fieldname = parser.getCurrentName();
            System.out.println("fieldname: " + fieldname);
        }
        valid = true;
    } catch (JsonParseException jpe) {
        jpe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    return valid;
}
 
Example #13
Source File: JsonDataValidator.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean isEmptySON(String json) {
    boolean isEmpty = true;
    try {
        final JsonParser parser = new ObjectMapper().getJsonFactory()
                .createJsonParser(json);
        while (parser.nextToken() != null) {
            String fieldname = parser.getCurrentName();
            if(fieldname != null){
                isEmpty = false;
                break;
            }

        }

    } catch (JsonParseException jpe) {
        System.out.println("isEmptySON: " + jpe.getMessage());
        jpe.printStackTrace();
    } catch (IOException ioe) {
        System.out.println("isEmptySON: " + ioe.getMessage());
        ioe.printStackTrace();
    }

    return isEmpty;
}
 
Example #14
Source File: DidReferenceResolutionTest.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Test
public void resolvesSessionRefDidsInCourseOfferingCorrectly() throws JsonParseException, JsonMappingException,
        IOException {
    NeutralRecordEntity entity = loadEntity("didTestEntities/courseOffering.json");
    resolveInternalId(entity);

    Map<String, String> edOrgNaturalKeys = new HashMap<String, String>();
    edOrgNaturalKeys.put("stateOrganizationId", "testSchoolId");
    String edOrgId = generateExpectedDid(edOrgNaturalKeys, TENANT_ID, "educationOrganization", null);

    Map<String, String> sessionNaturalKeys = new HashMap<String, String>();
    sessionNaturalKeys.put("schoolId", edOrgId);
    sessionNaturalKeys.put("sessionId", "theSessionName");

    checkId(entity, "SessionReference", sessionNaturalKeys, "session");
}
 
Example #15
Source File: PubSubWebSocketClient.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(String message)
{
  PubSubMessage<Object> pubSubMessage;
  try {
    pubSubMessage = codec.parseMessage(message);
    PubSubWebSocketClient.this.onMessage(pubSubMessage.getType().getIdentifier(), pubSubMessage.getTopic(), pubSubMessage.getData());
  } catch (JsonParseException jpe) {
    logger.warn("Ignoring unparseable JSON message: {}", message, jpe);
  } catch (JsonMappingException jme) {
    logger.warn("Ignoring JSON mapping in message: {}", message, jme);
  } catch (IOException ex) {
    onError(ex);
  }
}
 
Example #16
Source File: SiteToSiteRestApiClient.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private <T> T execute(final HttpGet get, final Class<T> entityClass) throws IOException {
    get.setHeader("Accept", "application/json");
    final String responseMessage = execute(get);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    try {
        return mapper.readValue(responseMessage, entityClass);
    } catch (JsonParseException e) {
        final String msg = "Failed to parse Json. The specified URL " + baseUrl + " is not a proper remote NiFi endpoint for Site-to-Site communication.";
        logger.warn("{} requestedUrl={}, response={}", msg, get.getURI(), responseMessage);
        throw new IOException(msg, e);
    }
}
 
Example #17
Source File: JsonParseExceptionMapper.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(JsonParseException ex) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", ex, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, ex);
    }

    return Response.status(Response.Status.BAD_REQUEST).entity("Unable to parse body as JSON.").type("text/plain").build();
}
 
Example #18
Source File: ImportRecord.java    From boubei-tss with Apache License 2.0 5 votes vote down vote up
public int createRecords(String json, String dataSource, Long groupId)
		throws IOException, JsonParseException, JsonMappingException {
	
       int count = 0;
   	Map<Long, Long> idMapping = new HashMap<Long, Long>();
   	
   	List<?> list = new ObjectMapper().readValue(json, List.class);
       for (int i = 0; i < list.size(); i++) {
       	Object obj = list.get(i);  // Map
           Record record = new ObjectMapper().readValue(EasyUtils.obj2Json(obj), Record.class);
           Long oldId = record.getId();
           
           record.setId(null);
           if ( i == 0 ) {
               record.setParentId(groupId);
           } else {
               Long parentId = idMapping.get(record.getParentId());
               parentId = (Long) EasyUtils.checkNull(parentId, groupId);
			record.setParentId(parentId);
           }
           
           if( Record.TYPE1 == record.getType() ) {
           	count ++;
           	record.setDatasource(dataSource);
           	
           	String table = record.getTable();
               record.setTable( table.substring(table.indexOf(".") + 1) ); // 去掉表空间|schema
           }
           
           Integer status = record.getDisabled();
           recordService.createRecord(record);
           
           record.setDisabled(status);
           recordService.updateRecord(record);
           
           idMapping.put(oldId, record.getId());
       }
	return count;
}
 
Example #19
Source File: ImportReport.java    From boubei-tss with Apache License 2.0 5 votes vote down vote up
public int createReports(String json, String dataSource, Long groupId)
		throws IOException, JsonParseException, JsonMappingException {
	
       int count = 0;
   	Map<Long, Long> idMapping = new HashMap<Long, Long>();
   	
   	List<?> list = new ObjectMapper().readValue(json, List.class);
       for (int i = 0; i < list.size(); i++) {
       	Object obj = list.get(i);  // Map
           Report report = new ObjectMapper().readValue(EasyUtils.obj2Json(obj), Report.class);
           Long oldId = report.getId();
           
           report.setId(null);
           if ( i == 0 ) {
               report.setParentId(groupId);
           } else {
               report.setParentId(idMapping.get(report.getParentId()));
           }
           
           if( !report.isGroup() ) {
           	count ++;
           	report.setDatasource(dataSource);
           }
           
           Integer status = report.getDisabled();
           reportService.createReport(report);
           
           report.setDisabled(status); // 因默认创建分组都是停用状态,但导入分组不需要,保留原来状态
           reportService.updateReport(report);
           
           idMapping.put(oldId, report.getId());
       }
	return count;
}
 
Example #20
Source File: Utils.java    From openmrs-module-initializer with MIT License 5 votes vote down vote up
/**
 * Convenience method to read a list of string out of a JSON string.
 */
public static List<String> asStringList(String jsonString) throws JsonParseException, JsonMappingException, IOException {
	List<Object> list = (new ObjectMapper()).readValue(jsonString, List.class);
	
	List<String> stringList = new ArrayList<String>();
	for (Object o : list) {
		stringList.add(asString(o));
	}
	return stringList;
}
 
Example #21
Source File: JsonSerDeser.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Convert from JSON
 *
 * @param json input
 * @return the parsed JSON
 * @throws IOException IO
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings("unchecked")
public synchronized T fromJson(String json)
    throws IOException, JsonParseException, JsonMappingException {
  try {
    return mapper.readValue(json, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json : " + e + "\n" + json, e);
    throw e;
  }
}
 
Example #22
Source File: JsonSerDeser.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Convert from a JSON file
 * @param jsonFile input file
 * @return the parsed JSON
 * @throws IOException IO problems
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings("unchecked")
public synchronized T fromFile(File jsonFile)
    throws IOException, JsonParseException, JsonMappingException {
  try {
    return mapper.readValue(jsonFile, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json file {}: {}", jsonFile, e);
    throw e;
  }
}
 
Example #23
Source File: JsonSerDeser.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Load from a Hadoop filesystem
 * @param fs filesystem
 * @param path path
 * @return a loaded CD
 * @throws IOException IO problems
 * @throws EOFException if not enough bytes were read in
 * @throws JsonParseException parse problems
 * @throws JsonMappingException O/J mapping problems
 */
public T load(FileSystem fs, Path path)
    throws IOException, JsonParseException, JsonMappingException {
  FileStatus status = fs.getFileStatus(path);
  long len = status.getLen();
  byte[] b = new byte[(int) len];
  FSDataInputStream dataInputStream = fs.open(path);
  int count = dataInputStream.read(b);
  if (count != len) {
    throw new EOFException(path.toString() + ": read finished prematurely");
  }
  return fromBytes(path.toString(), b);
}
 
Example #24
Source File: DatasourceServletAction.java    From ureport with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, Object> buildParameters(String parameters) throws IOException, JsonParseException, JsonMappingException {
	Map<String,Object> map=new HashMap<String,Object>();
	if(StringUtils.isBlank(parameters)){
		return map;
	}
	ObjectMapper mapper=new ObjectMapper();
	List<Map<String,Object>> list=mapper.readValue(parameters, ArrayList.class);
	for(Map<String,Object> param:list){
		String name=param.get("name").toString();
		DataType type=DataType.valueOf(param.get("type").toString());
		String defaultValue=(String)param.get("defaultValue");
		if(defaultValue==null || defaultValue.equals("")){
			switch(type){
			case Boolean:
				map.put(name, false);
			case Date:
				map.put(name, new Date());
			case Float:
				map.put(name, new Float(0));
			case Integer:
				map.put(name, 0);
			case String:
				if(defaultValue!=null && defaultValue.equals("")){
					map.put(name, "");						
				}else{
					map.put(name, "null");						
				}
				break;
			case List:
				map.put(name, new ArrayList<Object>());
			}				
		}else{
			map.put(name, type.parse(defaultValue));			
		}
	}
	return map;
}
 
Example #25
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private com.esri.ges.spatial.Geometry constructBuffer(Geometry geo, double radius, Unit u) throws GeometryException, JsonParseException, IOException
{
	
	com.esri.core.geometry.Geometry buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u);
	com.esri.core.geometry.Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #26
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructBuffer(Geometry geo, double radius, Unit u) throws JsonParseException, IOException
{
	
	Polygon buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u);
	Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	MapGeometry mapGeo = new MapGeometry(bufferout, srOut);
	return mapGeo;
	//String json = GeometryEngine.geometryToJson(srOut, bufferout);
	//return spatial.fromJson(json);
	
}
 
Example #27
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Map<String, Object> objGeo, SpatialReference inputSr, String units) throws JsonParseException, IOException
{
	Geometry geo = generateGeoFromMap(objGeo);
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}
 
Example #28
Source File: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructBuffer(Geometry geo, double radius, Unit u)
		throws JsonParseException, IOException {
	Polygon buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u);
	Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	MapGeometry mapGeo = new MapGeometry(bufferout, srOut);
	return mapGeo;
}
 
Example #29
Source File: GeoDynamoDBServlet.java    From dynamodb-geo with Apache License 2.0 5 votes vote down vote up
private void printGetPointRequest(GetPointResult getPointResult, PrintWriter out) throws JsonParseException,
		IOException {
	Map<String, AttributeValue> item = getPointResult.getGetItemResult().getItem();
	String geoJsonString = item.get(config.getGeoJsonAttributeName()).getS();
	JsonParser jsonParser = factory.createJsonParser(geoJsonString);
	JsonNode jsonNode = mapper.readTree(jsonParser);

	double latitude = jsonNode.get("coordinates").get(0).getDoubleValue();
	double longitude = jsonNode.get("coordinates").get(1).getDoubleValue();
	String hashKey = item.get(config.getHashKeyAttributeName()).getN();
	String rangeKey = item.get(config.getRangeKeyAttributeName()).getS();
	String geohash = item.get(config.getGeohashAttributeName()).getN();
	String schoolName = item.get("schoolName").getS();
	String memo = "";
	if (item.containsKey("memo")) {
		memo = item.get("memo").getS();
	}

	Map<String, String> resultMap = new HashMap<String, String>();
	resultMap.put("latitude", Double.toString(latitude));
	resultMap.put("longitude", Double.toString(longitude));
	resultMap.put("hashKey", hashKey);
	resultMap.put("rangeKey", rangeKey);
	resultMap.put("geohash", geohash);
	resultMap.put("schoolName", schoolName);
	resultMap.put("memo", memo);

	Map<String, Object> jsonMap = new HashMap<String, Object>();
	jsonMap.put("action", "get-point");
	jsonMap.put("result", resultMap);

	out.println(mapper.writeValueAsString(jsonMap));
	out.flush();
}
 
Example #30
Source File: JsonSerDeser.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Convert from JSON
 *
 * @param json input
 * @return the parsed JSON
 * @throws IOException IO
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings("unchecked")
public synchronized T fromJson(String json)
    throws IOException, JsonParseException, JsonMappingException {
  try {
    return mapper.readValue(json, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json : " + e + "\n" + json, e);
    throw e;
  }
}