@Test public void testMarshal() { UserPreferences up = new UserPreferences(); up.setShowCqlCompletionHint(false); String res = marshaller.marshal(up); assertEquals( "{\"e_hi\":\"0\",\"e_he\":\"1\",\"e_ro\":0,\"i_hi\":\"1\",\"i_ce\":\"0\",\"i_pa\":\"0\",\"p_ei\":5,\"p_hi\":50,\"p_ii\":100}", res); }
public @NotNull String marshal(@NotNull Object obj) { byte[] marshalBytes; try { marshalBytes = objectMapper.get().writeValueAsBytes(obj); } catch (IOException e) { throw new ServiceException("Gout IOException during json marshalling: " + e.getMessage() + " - input:'" + obj + "'", e); } try { String marshal = new String(marshalBytes, "UTF-8"); LOG.trace("Marshalled JSON from {} to {}", obj, marshal); return marshal; } catch (UnsupportedEncodingException e) { throw new ServiceException("UnsupportedEncodingException marshalling Json stream: " + e.getMessage() + " - input:'" + obj + "'", e); } }
JsonMarshaller { public @NotNull String marshal(@NotNull Object obj) { byte[] marshalBytes; try { marshalBytes = objectMapper.get().writeValueAsBytes(obj); } catch (IOException e) { throw new ServiceException("Gout IOException during json marshalling: " + e.getMessage() + " - input:'" + obj + "'", e); } try { String marshal = new String(marshalBytes, "UTF-8"); LOG.trace("Marshalled JSON from {} to {}", obj, marshal); return marshal; } catch (UnsupportedEncodingException e) { throw new ServiceException("UnsupportedEncodingException marshalling Json stream: " + e.getMessage() + " - input:'" + obj + "'", e); } } }
JsonMarshaller { public @NotNull String marshal(@NotNull Object obj) { byte[] marshalBytes; try { marshalBytes = objectMapper.get().writeValueAsBytes(obj); } catch (IOException e) { throw new ServiceException("Gout IOException during json marshalling: " + e.getMessage() + " - input:'" + obj + "'", e); } try { String marshal = new String(marshalBytes, "UTF-8"); LOG.trace("Marshalled JSON from {} to {}", obj, marshal); return marshal; } catch (UnsupportedEncodingException e) { throw new ServiceException("UnsupportedEncodingException marshalling Json stream: " + e.getMessage() + " - input:'" + obj + "'", e); } } JsonMarshaller(); }
JsonMarshaller { public @NotNull String marshal(@NotNull Object obj) { byte[] marshalBytes; try { marshalBytes = objectMapper.get().writeValueAsBytes(obj); } catch (IOException e) { throw new ServiceException("Gout IOException during json marshalling: " + e.getMessage() + " - input:'" + obj + "'", e); } try { String marshal = new String(marshalBytes, "UTF-8"); LOG.trace("Marshalled JSON from {} to {}", obj, marshal); return marshal; } catch (UnsupportedEncodingException e) { throw new ServiceException("UnsupportedEncodingException marshalling Json stream: " + e.getMessage() + " - input:'" + obj + "'", e); } } JsonMarshaller(); @NotNull T unmarshal(@NotNull Class<T> clazz, @NotNull @NotEmpty String input); @NotNull String marshal(@NotNull Object obj); }
JsonMarshaller { public @NotNull String marshal(@NotNull Object obj) { byte[] marshalBytes; try { marshalBytes = objectMapper.get().writeValueAsBytes(obj); } catch (IOException e) { throw new ServiceException("Gout IOException during json marshalling: " + e.getMessage() + " - input:'" + obj + "'", e); } try { String marshal = new String(marshalBytes, "UTF-8"); LOG.trace("Marshalled JSON from {} to {}", obj, marshal); return marshal; } catch (UnsupportedEncodingException e) { throw new ServiceException("UnsupportedEncodingException marshalling Json stream: " + e.getMessage() + " - input:'" + obj + "'", e); } } JsonMarshaller(); @NotNull T unmarshal(@NotNull Class<T> clazz, @NotNull @NotEmpty String input); @NotNull String marshal(@NotNull Object obj);  }