use of org.codehaus.jackson.map.JsonMappingException in project OpenAttestation by OpenAttestation.
the class DemoPortalDataController method saveNewHostInfo.
public ModelAndView saveNewHostInfo(HttpServletRequest req, HttpServletResponse res) {
log.info("WLMDataController.saveNewHostInfo >>");
ModelAndView responseView = new ModelAndView(new JSONView());
String hostObject = null;
boolean newhost = false;
try {
hostObject = req.getParameter("hostObject");
newhost = Boolean.parseBoolean(req.getParameter("newhost"));
} catch (Exception e1) {
responseView.addObject("result", false);
responseView.addObject("message", e1.getMessage());
}
System.out.println(hostObject);
ObjectMapper mapper = new ObjectMapper();
HostDetailsEntityVO dataVO = new HostDetailsEntityVO();
try {
dataVO = mapper.readValue(hostObject, HostDetailsEntityVO.class);
} catch (JsonParseException e) {
log.error("Error While Parsing request parameters Data. " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Parsing request parameters Data.");
return responseView;
} catch (JsonMappingException e) {
log.error("Error While Mapping request parameters to Mle Data Object. " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
return responseView;
} catch (IOException e) {
log.error("IO Exception " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
return responseView;
}
dataVO.setUpdatedOn(new Date(System.currentTimeMillis()));
try {
if (newhost) {
System.err.println("dataForNew : " + dataVO);
responseView.addObject("result", demoPortalServices.saveNewHostData(dataVO, getAttestationService(req, AttestationService.class)));
} else {
System.err.println("dataForOLD : " + dataVO);
responseView.addObject("result", demoPortalServices.updateHostData(dataVO, getAttestationService(req, AttestationService.class)));
}
} catch (DemoPortalException e) {
log.error(e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", e.getMessage());
return responseView;
}
log.info("WLMDataController.saveNewHostInfo <<<");
return responseView;
}
use of org.codehaus.jackson.map.JsonMappingException in project openhab1-addons by openhab.
the class FritzahaQueryscriptUpdateNumberCallback method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(int status, String response) {
super.execute(status, response);
if (validRequest) {
logger.debug("Received State response " + response + " for item " + itemName);
String valueType;
if (type == MeterType.VOLTAGE) {
valueType = "MM_Value_Volt";
} else if (type == MeterType.CURRENT) {
valueType = "MM_Value_Amp";
} else if (type == MeterType.POWER) {
valueType = "MM_Value_Power";
} else if (type == MeterType.ENERGY) {
valueType = "";
} else {
return;
}
ObjectMapper jsonReader = new ObjectMapper();
Map<String, String> deviceData;
try {
deviceData = jsonReader.readValue(response, Map.class);
} catch (JsonParseException e) {
logger.error("Error parsing JSON:\n" + response);
return;
} catch (JsonMappingException e) {
logger.error("Error mapping JSON:\n" + response);
return;
} catch (IOException e) {
logger.error("An I/O error occured while decoding JSON:\n" + response);
return;
}
if (type == MeterType.ENERGY) {
String ValIdent = "EnStats_watt_value_";
long valCount = Long.parseLong(deviceData.get("EnStats_count"));
BigDecimal meterValue = new BigDecimal(0);
BigDecimal meterValueScaled;
long tmplong;
BigDecimal tmpBD;
for (int tmpcnt = 1; tmpcnt <= valCount; tmpcnt++) {
tmplong = Long.parseLong(deviceData.get(ValIdent + tmpcnt));
meterValue = meterValue.add(new BigDecimal(tmplong));
}
if (Long.parseLong(deviceData.get("EnStats_timer_type")) == 10) {
// 10 Minute values are given in mWh, so scale to Wh
meterValueScaled = meterValue.scaleByPowerOfTen(-6);
} else {
// Other values are given in Wh, so scale to kWh
meterValueScaled = meterValue.scaleByPowerOfTen(-3);
}
webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
} else if (deviceData.containsKey(valueType)) {
BigDecimal meterValue = new BigDecimal(deviceData.get(valueType));
BigDecimal meterValueScaled;
switch(type) {
case VOLTAGE:
meterValueScaled = meterValue.scaleByPowerOfTen(-3);
break;
case CURRENT:
meterValueScaled = meterValue.scaleByPowerOfTen(-4);
break;
case POWER:
meterValueScaled = meterValue.scaleByPowerOfTen(-2);
break;
default:
meterValueScaled = meterValue;
}
webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
} else {
logger.error("Response did not contain " + valueType);
}
}
}
use of org.codehaus.jackson.map.JsonMappingException in project openhab1-addons by openhab.
the class FritzahaQueryscriptUpdateSwitchCallback method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(int status, String response) {
super.execute(status, response);
if (validRequest) {
logger.debug("Received State response " + response + " for item " + itemName);
ObjectMapper jsonReader = new ObjectMapper();
Map<String, String> deviceData;
try {
deviceData = jsonReader.readValue(response, Map.class);
} catch (JsonParseException e) {
logger.error("Error parsing JSON:\n" + response);
return;
} catch (JsonMappingException e) {
logger.error("Error mapping JSON:\n" + response);
return;
} catch (IOException e) {
logger.error("An I/O error occured while decoding JSON:\n" + response);
return;
}
if (deviceData.containsKey("DeviceSwitchState")) {
webIface.postUpdate(itemName, "1".equals(deviceData.get("DeviceSwitchState")) ? OnOffType.ON : OnOffType.OFF);
}
}
}
use of org.codehaus.jackson.map.JsonMappingException in project neo4j by neo4j.
the class StatementDeserializer method fetchNextOrNull.
@Override
protected Statement fetchNextOrNull() {
try {
if (errors != null) {
return null;
}
switch(state) {
case BEFORE_OUTER_ARRAY:
if (!beginsWithCorrectTokens()) {
return null;
}
state = State.IN_BODY;
case IN_BODY:
String statement = null;
Map<String, Object> parameters = null;
List<Object> resultsDataContents = null;
boolean includeStats = false;
JsonToken tok;
while ((tok = input.nextToken()) != null && tok != END_OBJECT) {
if (tok == END_ARRAY) {
// No more statements
state = State.FINISHED;
return null;
}
input.nextValue();
String currentName = input.getCurrentName();
switch(currentName) {
case "statement":
statement = input.readValueAs(String.class);
break;
case "parameters":
parameters = readMap(input);
break;
case "resultDataContents":
resultsDataContents = readArray(input);
break;
case "includeStats":
includeStats = input.getBooleanValue();
break;
default:
discardValue(input);
}
}
if (statement == null) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("No statement provided.")));
return null;
}
return new Statement(statement, parameters == null ? NO_PARAMETERS : parameters, includeStats, ResultDataContent.fromNames(resultsDataContents));
case FINISHED:
return null;
default:
break;
}
return null;
} catch (JsonParseException | JsonMappingException e) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request", e)));
return null;
} catch (IOException e) {
addError(new Neo4jError(Status.Network.CommunicationError, e));
return null;
} catch (Exception e) {
addError(new Neo4jError(Status.General.UnknownError, e));
return null;
}
}
use of org.codehaus.jackson.map.JsonMappingException in project ranger by apache.
the class JSONUtil method writeObjectAsString.
public String writeObjectAsString(Serializable obj) {
ObjectMapper mapper = new ObjectMapper();
String jsonStr;
try {
jsonStr = mapper.writeValueAsString(obj);
return jsonStr;
} catch (JsonParseException e) {
throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
} catch (JsonMappingException e) {
throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
} catch (IOException e) {
throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
}
}
Aggregations