Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. @Override
  2. public void configureMessageConverters(
  3. List<HttpMessageConverter<?>> converters) {
  4. //Added string converter to avoid scape " and the addition of " at the beginning of the Json
  5. converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
  6. converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
  7.  
  8. }
  9.  
  10. @Bean
  11. public ObjectMapper objectMapper() {
  12. ObjectMapper objectMapper = new ObjectMapper();
  13. objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  14. objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  15. objectMapper.registerModule(new JodaMoneyModule());
  16. objectMapper.registerModule(new JodaModule());
  17. //objectMapper.registerModule(new AmountModule());
  18. objectMapper.getFactory().setCharacterEscapes(new JavascriptCharacterEscapes());
  19. return objectMapper;
  20.  
  21. }
  22.  
  23. public class AmountModule extends SimpleModule
  24. {
  25. private static final long serialVersionUID = 1L;
  26.  
  27. public AmountModule()
  28. {
  29. super();
  30.  
  31. // then serializers:
  32. addSerializer(Amount.class, new AmountSerializer());
  33.  
  34. }
  35. }
  36.  
  37. public class AmountSerializer extends JsonSerializer<Amount> {
  38.  
  39. @Override
  40. public void serialize(Amount amount, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
  41. if (amount!=null) {
  42. try {
  43. amount.setValue(webParamEncryptor.encryptWebParam(amount.getValue().toPlainString()));
  44. jgen.writeObject(amount);
  45. } catch (Exception e) {
  46. logger.error("Error to marshal date", e);
  47. }
  48. } else {
  49. jgen.writeNull();
  50. }
  51.  
  52. }
  53. }
  54.  
  55. public class Amount extends Currency {
  56. private static final long serialVersionUID = 1L;
  57.  
  58. @JsonProperty("value")
  59. private String value = null;
  60.  
  61. @JsonProperty("customDisplay")
  62. private String customDisplay = null;
  63.  
  64. private boolean roundToCurrencyDecimals= true;
  65.  
  66. public class Account implements Serializable {
  67. private static final long serialVersionUID = 1L;
  68.  
  69. @JsonProperty("id")
  70. private int id;
  71.  
  72. @JsonIgnore
  73. private String number = null;
  74.  
  75. @JsonIgnore
  76. private Amount balance = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement