use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ma-modules-public by infiniteautomation.
the class MangoV2WebSocketHandler method sendMessageUsingView.
protected void sendMessageUsingView(WebSocketSession session, WebSocketMessage message, Class<?> view) throws JsonProcessingException {
ObjectWriter objectWriter = this.jacksonMapper.writerWithView(view);
this.sendStringMessage(session, objectWriter.writeValueAsString(message));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ma-modules-public by infiniteautomation.
the class UserFunctionalTests method testAdminCreateUser.
/**
* Test Creating a User
* TODO This test fails!!!! Because we don't render the password in the JSON property yet. :(
*/
public void testAdminCreateUser() {
User standardUser = UserTestData.standardUser();
User adminUser = UserTestData.adminUser();
List<User> users = new ArrayList<>();
users.add(standardUser);
// This will ensure that the getUsers() method returns
// the mock list of users
when(userDao.getUser(standardUser.getUsername())).thenReturn(null);
ObjectWriter writer = this.objectMapper.writerWithView(JsonViews.Test.class);
try {
String userJson = writer.writeValueAsString(new UserModel(standardUser));
this.mockMvc.perform(post("/v1/users/").content(userJson).contentType(MediaType.APPLICATION_JSON).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ma-modules-public by infiniteautomation.
the class DataSourceFunctionalTests method testAdminUpdate.
/**
* Test udpating a mock data source
*/
public void testAdminUpdate() {
DataSourceVO ds = DataSourceTestData.mockDataSource();
when(dataSourceDao.getByXid(ds.getXid())).thenReturn(ds);
User adminUser = UserTestData.adminUser();
ObjectWriter writer = this.objectMapper.writerWithView(JsonViews.Test.class);
try {
String userJson = writer.writeValueAsString(new MockDataSourceModel((MockDataSourceVO) ds));
this.mockMvc.perform(put("/v1/dataSources/" + ds.getXid()).content(userJson).contentType(MediaType.APPLICATION_JSON).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project commons by craftercms.
the class CrafterJackson2MessageConverter method writeInternal.
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
JsonGenerator jsonGenerator = this.getObjectMapper().getFactory().createGenerator(outputMessage.getBody(), encoding);
// https://github.com/FasterXML/jackson-databind/issues/12
if (this.getObjectMapper().isEnabled(SerializationFeature.INDENT_OUTPUT)) {
jsonGenerator.useDefaultPrettyPrinter();
}
try {
if (this.jsonPrefix != null) {
jsonGenerator.writeRaw(this.jsonPrefix);
}
runAnnotations(object);
ObjectWriter writer = this.getObjectMapper().writer(filter);
writer.writeValue(jsonGenerator, object);
} catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project kylo by Teradata.
the class JwtRememberMeServices method generatePrincipalsToken.
/**
* Serializes principal information derived from the supplied authorities as a JSON string
* that can be deserialized back into a set of authorities containing those Principal objects.
* @param collection the authorities produced after login
* @return a JSON string describing the principals derived from the authorities
*/
protected String generatePrincipalsToken(Collection<? extends GrantedAuthority> authorities) {
PrincipalsToken token = new PrincipalsToken();
ObjectWriter writer = mapper.writer().forType(PrincipalsToken.class);
for (GrantedAuthority authority : authorities) {
token.add(authority);
}
try {
return writer.writeValueAsString(token);
} catch (JsonProcessingException e) {
// Shouldn't really happen
throw new IllegalStateException("Unable to serialize principals for JWT token", e);
}
}
Aggregations