Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void configureMessageConverters(
- List<HttpMessageConverter<?>> converters) {
- //Added string converter to avoid scape " and the addition of " at the beginning of the Json
- converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
- converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
- }
- @Bean
- public ObjectMapper objectMapper() {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- objectMapper.registerModule(new JodaMoneyModule());
- objectMapper.registerModule(new JodaModule());
- //objectMapper.registerModule(new AmountModule());
- objectMapper.getFactory().setCharacterEscapes(new JavascriptCharacterEscapes());
- return objectMapper;
- }
- public class AmountModule extends SimpleModule
- {
- private static final long serialVersionUID = 1L;
- public AmountModule()
- {
- super();
- // then serializers:
- addSerializer(Amount.class, new AmountSerializer());
- }
- }
- public class AmountSerializer extends JsonSerializer<Amount> {
- @Override
- public void serialize(Amount amount, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
- if (amount!=null) {
- try {
- amount.setValue(webParamEncryptor.encryptWebParam(amount.getValue().toPlainString()));
- jgen.writeObject(amount);
- } catch (Exception e) {
- logger.error("Error to marshal date", e);
- }
- } else {
- jgen.writeNull();
- }
- }
- }
- public class Amount extends Currency {
- private static final long serialVersionUID = 1L;
- @JsonProperty("value")
- private String value = null;
- @JsonProperty("customDisplay")
- private String customDisplay = null;
- private boolean roundToCurrencyDecimals= true;
- public class Account implements Serializable {
- private static final long serialVersionUID = 1L;
- @JsonProperty("id")
- private int id;
- @JsonIgnore
- private String number = null;
- @JsonIgnore
- private Amount balance = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement