@Test public void testBasicConvertIntKey() throws Exception { int key = 5; String testContent = "hello world"; Record record = new Record(key, testContent); Converter<String, String, Object, RawJsonDocument> recordConverter = new AnyToCouchbaseJsonConverter(); RawJsonDocument returnDoc = recordConverter.convertRecord("", record, null).iterator().next(); Assert.assertEquals(key+"", returnDoc.id(), "key should be equal"); Record convertedRecord = GSON.fromJson(returnDoc.content(), Record.class); Assert.assertEquals(convertedRecord.key, key); Assert.assertEquals(convertedRecord.value, testContent, "value in content should be equal"); }
@Override public Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement jsonElement = GSON.toJsonTree(inputRecord); if (!jsonElement.isJsonObject()) { throw new DataConversionException("Expecting json element " + jsonElement.toString() + " to be of type JsonObject."); } JsonObject jsonObject = jsonElement.getAsJsonObject(); if (!jsonObject.has(keyField)) { throw new DataConversionException("Could not find key field " + keyField + " in json object " + jsonObject.toString()); } JsonElement keyValueElement = jsonObject.get(keyField); String keyString; try { keyString = keyValueElement.getAsString(); } catch (Exception e) { throw new DataConversionException("Could not get the key " + keyValueElement.toString() + " as a string", e); } String valueString = GSON.toJson(jsonElement); RawJsonDocument jsonDocument = RawJsonDocument.create(keyString, valueString); return new SingleRecordIterable<>(jsonDocument); }
AnyToCouchbaseJsonConverter extends Converter<String, String, Object, RawJsonDocument> { @Override public Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement jsonElement = GSON.toJsonTree(inputRecord); if (!jsonElement.isJsonObject()) { throw new DataConversionException("Expecting json element " + jsonElement.toString() + " to be of type JsonObject."); } JsonObject jsonObject = jsonElement.getAsJsonObject(); if (!jsonObject.has(keyField)) { throw new DataConversionException("Could not find key field " + keyField + " in json object " + jsonObject.toString()); } JsonElement keyValueElement = jsonObject.get(keyField); String keyString; try { keyString = keyValueElement.getAsString(); } catch (Exception e) { throw new DataConversionException("Could not get the key " + keyValueElement.toString() + " as a string", e); } String valueString = GSON.toJson(jsonElement); RawJsonDocument jsonDocument = RawJsonDocument.create(keyString, valueString); return new SingleRecordIterable<>(jsonDocument); } }
AnyToCouchbaseJsonConverter extends Converter<String, String, Object, RawJsonDocument> { @Override public Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement jsonElement = GSON.toJsonTree(inputRecord); if (!jsonElement.isJsonObject()) { throw new DataConversionException("Expecting json element " + jsonElement.toString() + " to be of type JsonObject."); } JsonObject jsonObject = jsonElement.getAsJsonObject(); if (!jsonObject.has(keyField)) { throw new DataConversionException("Could not find key field " + keyField + " in json object " + jsonObject.toString()); } JsonElement keyValueElement = jsonObject.get(keyField); String keyString; try { keyString = keyValueElement.getAsString(); } catch (Exception e) { throw new DataConversionException("Could not get the key " + keyValueElement.toString() + " as a string", e); } String valueString = GSON.toJson(jsonElement); RawJsonDocument jsonDocument = RawJsonDocument.create(keyString, valueString); return new SingleRecordIterable<>(jsonDocument); }  }
AnyToCouchbaseJsonConverter extends Converter<String, String, Object, RawJsonDocument> { @Override public Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement jsonElement = GSON.toJsonTree(inputRecord); if (!jsonElement.isJsonObject()) { throw new DataConversionException("Expecting json element " + jsonElement.toString() + " to be of type JsonObject."); } JsonObject jsonObject = jsonElement.getAsJsonObject(); if (!jsonObject.has(keyField)) { throw new DataConversionException("Could not find key field " + keyField + " in json object " + jsonObject.toString()); } JsonElement keyValueElement = jsonObject.get(keyField); String keyString; try { keyString = keyValueElement.getAsString(); } catch (Exception e) { throw new DataConversionException("Could not get the key " + keyValueElement.toString() + " as a string", e); } String valueString = GSON.toJson(jsonElement); RawJsonDocument jsonDocument = RawJsonDocument.create(keyString, valueString); return new SingleRecordIterable<>(jsonDocument); }  @Override Converter<String, String, Object, RawJsonDocument> init(WorkUnitState workUnit); @Override String convertSchema(String inputSchema, WorkUnitState workUnit); @Override Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit); }
AnyToCouchbaseJsonConverter extends Converter<String, String, Object, RawJsonDocument> { @Override public Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement jsonElement = GSON.toJsonTree(inputRecord); if (!jsonElement.isJsonObject()) { throw new DataConversionException("Expecting json element " + jsonElement.toString() + " to be of type JsonObject."); } JsonObject jsonObject = jsonElement.getAsJsonObject(); if (!jsonObject.has(keyField)) { throw new DataConversionException("Could not find key field " + keyField + " in json object " + jsonObject.toString()); } JsonElement keyValueElement = jsonObject.get(keyField); String keyString; try { keyString = keyValueElement.getAsString(); } catch (Exception e) { throw new DataConversionException("Could not get the key " + keyValueElement.toString() + " as a string", e); } String valueString = GSON.toJson(jsonElement); RawJsonDocument jsonDocument = RawJsonDocument.create(keyString, valueString); return new SingleRecordIterable<>(jsonDocument); }  @Override Converter<String, String, Object, RawJsonDocument> init(WorkUnitState workUnit); @Override String convertSchema(String inputSchema, WorkUnitState workUnit); @Override Iterable<RawJsonDocument> convertRecord(String outputSchema, Object inputRecord, WorkUnitState workUnit); static final String KEY_FIELD_CONFIG; }