@Test public void testSwitchingOrderOfMainDoc() throws Exception { Metadata m1 = new Metadata(); m1.add("k1", "v1"); m1.add("k1", "v2"); m1.add("k1", "v3"); m1.add("k1", "v4"); m1.add("k1", "v4"); m1.add("k2", "v1"); m1.add(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH, "/embedded-1"); Metadata m2 = new Metadata(); m2.add("k3", "v1"); m2.add("k3", "v2"); m2.add("k3", "v3"); m2.add("k3", "v4"); m2.add("k3", "v4"); m2.add("k4", "v1"); List<Metadata> truth = new ArrayList<>(); truth.add(m2); truth.add(m1); StringWriter stringWriter = new StringWriter(); try(JsonStreamingSerializer serializer = new JsonStreamingSerializer(stringWriter)) { serializer.add(m1); serializer.add(m2); } Reader reader = new StringReader(stringWriter.toString()); List<Metadata> deserialized = JsonMetadataList.fromJson(reader); assertEquals(truth, deserialized); }
public static List<Metadata> fromJson(Reader reader) throws TikaException { List<Metadata> ms = null; if (reader == null) { return ms; } try { ms = GSON.fromJson(reader, listType); } catch (com.google.gson.JsonParseException e){ throw new TikaException(e.getMessage()); } if (ms == null) { return null; } if (ms.size() > 1) { Metadata last = ms.get(ms.size()-1); String embResourcePath = last.get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH); if (embResourcePath == null && ms.get(0).get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH) != null) { ms.add(0, ms.remove(ms.size()-1)); } } return ms; }
JsonMetadataList extends JsonMetadataBase { public static List<Metadata> fromJson(Reader reader) throws TikaException { List<Metadata> ms = null; if (reader == null) { return ms; } try { ms = GSON.fromJson(reader, listType); } catch (com.google.gson.JsonParseException e){ throw new TikaException(e.getMessage()); } if (ms == null) { return null; } if (ms.size() > 1) { Metadata last = ms.get(ms.size()-1); String embResourcePath = last.get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH); if (embResourcePath == null && ms.get(0).get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH) != null) { ms.add(0, ms.remove(ms.size()-1)); } } return ms; } }
JsonMetadataList extends JsonMetadataBase { public static List<Metadata> fromJson(Reader reader) throws TikaException { List<Metadata> ms = null; if (reader == null) { return ms; } try { ms = GSON.fromJson(reader, listType); } catch (com.google.gson.JsonParseException e){ throw new TikaException(e.getMessage()); } if (ms == null) { return null; } if (ms.size() > 1) { Metadata last = ms.get(ms.size()-1); String embResourcePath = last.get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH); if (embResourcePath == null && ms.get(0).get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH) != null) { ms.add(0, ms.remove(ms.size()-1)); } } return ms; }  }
JsonMetadataList extends JsonMetadataBase { public static List<Metadata> fromJson(Reader reader) throws TikaException { List<Metadata> ms = null; if (reader == null) { return ms; } try { ms = GSON.fromJson(reader, listType); } catch (com.google.gson.JsonParseException e){ throw new TikaException(e.getMessage()); } if (ms == null) { return null; } if (ms.size() > 1) { Metadata last = ms.get(ms.size()-1); String embResourcePath = last.get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH); if (embResourcePath == null && ms.get(0).get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH) != null) { ms.add(0, ms.remove(ms.size()-1)); } } return ms; }  static void toJson(List<Metadata> metadataList, Writer writer); static List<Metadata> fromJson(Reader reader); static void setGson(Gson gson); static void setPrettyPrinting(boolean prettyPrint); }
JsonMetadataList extends JsonMetadataBase { public static List<Metadata> fromJson(Reader reader) throws TikaException { List<Metadata> ms = null; if (reader == null) { return ms; } try { ms = GSON.fromJson(reader, listType); } catch (com.google.gson.JsonParseException e){ throw new TikaException(e.getMessage()); } if (ms == null) { return null; } if (ms.size() > 1) { Metadata last = ms.get(ms.size()-1); String embResourcePath = last.get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH); if (embResourcePath == null && ms.get(0).get(RecursiveParserWrapperHandler.EMBEDDED_RESOURCE_PATH) != null) { ms.add(0, ms.remove(ms.size()-1)); } } return ms; }  static void toJson(List<Metadata> metadataList, Writer writer); static List<Metadata> fromJson(Reader reader); static void setGson(Gson gson); static void setPrettyPrinting(boolean prettyPrint);  }