Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.oneconsult.seoc.api.util;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.va.oneconsult.seoc.api.json.SeocCreateResponse;
import gov.va.oneconsult.seoc.api.json.SeocGenericResponse;
import gov.va.oneconsult.seoc.api.model.User;
public class DeserializeTest
{
public static final Logger logger = EncodeLoggerFactory.getLogger(DeserializeTest.class);
/**
* Description:
* @return
*/
public SeocCreateResponse createResponse(String response)
{
//OuterWrapper outerWrapper = new OuterWrapper();
SeocCreateResponse responseWrapper = new SeocCreateResponse();
ObjectMapper mapper = new ObjectMapper();
try
{
responseWrapper = mapper.readValue(response, SeocCreateResponse.class);
} catch (JsonParseException e)
{
logger.debug("Exception occured in deSerializeSeocCreateResponse." + e.getMessage());
} catch (JsonMappingException e)
{
logger.debug("Exception occured in deSerializeSeocCreateResponse." + e.getMessage());
} catch (IOException e)
{
logger.debug("Exception occured in deSerializeSeocCreateResponse." + e.getMessage());
}
return responseWrapper;
}
/**
* Description:
* @return
*/
public SeocGenericResponse genericResponse(String response)
{
//OuterWrapper outerWrapper = new OuterWrapper();
SeocGenericResponse responseWrapper = new SeocGenericResponse();
ObjectMapper mapper = new ObjectMapper();
try
{
responseWrapper = mapper.readValue(response, SeocGenericResponse.class);
} catch (JsonParseException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
} catch (JsonMappingException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
} catch (IOException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
}
return responseWrapper;
}
/**
* Description: Retrieve requested field value from the response Seoc object
* @param response
* @param field
* @return String
*/
public String seocResponse(String response, String field)
{
String value = null;
try
{
JSONObject obj = new JSONObject(response);
String seocStr = obj.getString("Seoc");
value = new JSONObject(seocStr).getString(field);
if(value!=null && value.equals("null")) {
return null;
}
} catch (JSONException e)
{
logger.debug("Exception occured in deSerialize Seoc Response." + e.getMessage());
}
return value;
}
/**
* Description: Get Set of User objects from the response JSON
* @param response
* @return Set<User>
*/
public Set<User> getUsersFromResponse(String response)
{
Set<User> users = new HashSet<User>();
ObjectMapper mapper = new ObjectMapper();
User wrapper = new User();
try
{
JSONArray array = new JSONArray(response);
JSONObject innerObj = null;
for(int i=0;i<array.length();i++) {
try
{
innerObj = (JSONObject)array.get(i);
wrapper = mapper.readValue(innerObj.toString(), User.class);
wrapper.setDomain(innerObj.getString("domain"));
wrapper.setVaNetworkId(innerObj.getString("vaNetworkId"));
users.add(wrapper);
} catch (JsonParseException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
} catch (JsonMappingException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
} catch (IOException e)
{
logger.debug("Exception occured in deSerializeSeocGenericResponse." + e.getMessage());
}
}
} catch (JSONException e)
{
logger.debug("Exception occured in deSerialize User Response." + e.getMessage());
}
return users;
}
}