@Test public void testValueNotFound() { BSONObject field = new BasicBSONObject("field", 123L); BSONObject entry = new BasicBSONObject("long", field); BSONWritable entity = new BSONWritable(entry); LongValueMapper mapper = new LongValueMapper("long.missing_field"); Writable value = mapper.getValue(entity); assertTrue(value instanceof NullWritable); }
@Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new LongWritable(Long.parseLong(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {'%s'} to Long", value)); } return rval; }
LongValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new LongWritable(Long.parseLong(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {'%s'} to Long", value)); } return rval; } }
LongValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new LongWritable(Long.parseLong(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {'%s'} to Long", value)); } return rval; } LongValueMapper(String fieldName); }
LongValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new LongWritable(Long.parseLong(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {'%s'} to Long", value)); } return rval; } LongValueMapper(String fieldName); @Override Writable getValue(BSONWritable entity); }
LongValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new LongWritable(Long.parseLong(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {'%s'} to Long", value)); } return rval; } LongValueMapper(String fieldName); @Override Writable getValue(BSONWritable entity);  }