use of com.fasterxml.jackson.databind.ObjectWriter in project topjava10 by JavaWebinar.
the class JsonUtilTest method testRestReadWriteValue.
@Test
public void testRestReadWriteValue() throws Exception {
ObjectWriter uiWriter = JacksonObjectMapper.getMapper().writerWithView(View.JsonUI.class);
String json = JsonUtil.writeValue(MealTestData.ADMIN_MEAL1, uiWriter);
System.out.println(json);
assertThat(json, containsString("dateTimeUI"));
}
use of com.fasterxml.jackson.databind.ObjectWriter in project CzechIdMng by bcvsolutions.
the class LoginControllerRestTest method serialize.
private String serialize(Map<String, String> login) throws IOException {
ObjectMapper m = new ObjectMapper();
StringWriter sw = new StringWriter();
ObjectWriter writer = m.writerFor(HashMap.class);
writer.writeValue(sw, login);
//
return sw.toString();
}
use of com.fasterxml.jackson.databind.ObjectWriter in project cas by apereo.
the class TicketValidationResourceResolver method resolveFrom.
@Override
public String[] resolveFrom(final JoinPoint joinPoint, final Object object) {
final List<String> auditResourceResults = new ArrayList<>();
final String ticketId = AopUtils.unWrapJoinPoint(joinPoint).getArgs()[0].toString();
auditResourceResults.add(ticketId);
if (object instanceof Assertion) {
final Assertion assertion = Assertion.class.cast(object);
final Authentication authn = assertion.getPrimaryAuthentication();
try (StringWriter writer = new StringWriter()) {
final ObjectWriter objectWriter = mapper.writer();
final Map<String, Object> results = new LinkedHashMap<>();
results.put("principal", authn.getPrincipal().getId());
final Map<String, Object> attributes = new LinkedHashMap<>(authn.getAttributes());
attributes.putAll(authn.getPrincipal().getAttributes());
results.put("attributes", attributes);
objectWriter.writeValue(writer, results);
auditResourceResults.add(writer.toString());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
return auditResourceResults.toArray(new String[] {});
}
use of com.fasterxml.jackson.databind.ObjectWriter in project uPortal by Jasig.
the class JpaStatisticalSummaryTest method testStorelessUnivariateStatistic.
public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected) throws Exception {
assertEquals(expected, sus.getResult(), 0.1);
final ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
// Configure Jackson to just use fields
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));
final ObjectWriter ssWriter = mapper.writer(filters);
final ObjectReader ssReader = mapper.reader(sus.getClass());
final String susString = ssWriter.writeValueAsString(sus);
System.out.println(susString);
final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
assertEquals(expected, newSus.getResult(), 0.1);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project graphhopper by graphhopper.
the class GHBaseServlet method writeJson.
protected void writeJson(HttpServletRequest req, HttpServletResponse res, JsonNode json) throws IOException {
String type = getParam(req, "type", "json");
res.setCharacterEncoding("UTF-8");
final boolean indent = getBooleanParam(req, "debug", false) || getBooleanParam(req, "pretty", false);
ObjectWriter objectWriter = indent ? objectMapper.writer().with(SerializationFeature.INDENT_OUTPUT) : objectMapper.writer();
if ("jsonp".equals(type)) {
res.setContentType("application/javascript");
if (!jsonpAllowed) {
writeError(res, SC_BAD_REQUEST, "Server is not configured to allow jsonp!");
return;
}
String callbackName = getParam(req, "callback", null);
if (callbackName == null) {
writeError(res, SC_BAD_REQUEST, "No callback provided, necessary if type=jsonp");
return;
}
writeResponse(res, callbackName + "(" + objectWriter.writeValueAsString(json) + ")");
} else {
res.setContentType("application/json");
writeResponse(res, objectWriter.writeValueAsString(json));
}
}
Aggregations