@Test public void testSerialize() throws Exception { VocabWord word = new VocabWord(1, "word"); AbstractElementFactory<VocabWord> factory = new AbstractElementFactory<>(VocabWord.class); System.out.println("VocabWord JSON: " + factory.serialize(word)); VocabWord word2 = factory.deserialize(factory.serialize(word)); assertEquals(word, word2); }
@Override public String serialize(T element) { String json = null; try { json = element.toJSON(); } catch (Exception e) { log.error("Direct serialization failed, falling back to jackson"); } if (json == null || json.isEmpty()) { ObjectMapper mapper = SequenceElement.mapper(); try { json = mapper.writeValueAsString(element); } catch (org.nd4j.shade.jackson.core.JsonProcessingException e) { throw new RuntimeException(e); } } return json; }
AbstractElementFactory implements SequenceElementFactory<T> { @Override public String serialize(T element) { String json = null; try { json = element.toJSON(); } catch (Exception e) { log.error("Direct serialization failed, falling back to jackson"); } if (json == null || json.isEmpty()) { ObjectMapper mapper = SequenceElement.mapper(); try { json = mapper.writeValueAsString(element); } catch (org.nd4j.shade.jackson.core.JsonProcessingException e) { throw new RuntimeException(e); } } return json; } }
AbstractElementFactory implements SequenceElementFactory<T> { @Override public String serialize(T element) { String json = null; try { json = element.toJSON(); } catch (Exception e) { log.error("Direct serialization failed, falling back to jackson"); } if (json == null || json.isEmpty()) { ObjectMapper mapper = SequenceElement.mapper(); try { json = mapper.writeValueAsString(element); } catch (org.nd4j.shade.jackson.core.JsonProcessingException e) { throw new RuntimeException(e); } } return json; } AbstractElementFactory(@NonNull Class<? extends SequenceElement> cls); }
AbstractElementFactory implements SequenceElementFactory<T> { @Override public String serialize(T element) { String json = null; try { json = element.toJSON(); } catch (Exception e) { log.error("Direct serialization failed, falling back to jackson"); } if (json == null || json.isEmpty()) { ObjectMapper mapper = SequenceElement.mapper(); try { json = mapper.writeValueAsString(element); } catch (org.nd4j.shade.jackson.core.JsonProcessingException e) { throw new RuntimeException(e); } } return json; } AbstractElementFactory(@NonNull Class<? extends SequenceElement> cls); @Override T deserialize(String json); @Override String serialize(T element); }
AbstractElementFactory implements SequenceElementFactory<T> { @Override public String serialize(T element) { String json = null; try { json = element.toJSON(); } catch (Exception e) { log.error("Direct serialization failed, falling back to jackson"); } if (json == null || json.isEmpty()) { ObjectMapper mapper = SequenceElement.mapper(); try { json = mapper.writeValueAsString(element); } catch (org.nd4j.shade.jackson.core.JsonProcessingException e) { throw new RuntimeException(e); } } return json; } AbstractElementFactory(@NonNull Class<? extends SequenceElement> cls); @Override T deserialize(String json); @Override String serialize(T element);  }