allow id & timestamp keys when converting to Tuple
also avoid possible NPE in the DefaultTuple toString() method
This commit is contained in:
committed by
Thomas Risberg
parent
68ce2d3a02
commit
4bec17ca1c
@@ -610,11 +610,14 @@ public class DefaultTuple implements Tuple {
|
||||
this.tupleToStringConverter = tupleToStringConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* The format is of the form DefaultTuple [names="n1'
|
||||
* Returns a JSON representation of this Tuple.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (tupleToStringConverter == null) {
|
||||
return new TupleToJsonStringConverter().convert(this);
|
||||
}
|
||||
return tupleToStringConverter.convert(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -24,7 +24,6 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class JsonNodeToTupleConverter implements Converter<JsonNode, Tuple> {
|
||||
|
||||
@@ -47,15 +46,7 @@ public class JsonNodeToTupleConverter implements Converter<JsonNode, Tuple> {
|
||||
builder.addEntry(name, nodeToList(node));
|
||||
}
|
||||
else {
|
||||
if (name.equals("id")) {//NOSONAR
|
||||
// TODO how should this be handled?
|
||||
}
|
||||
else if (name.equals("timestamp")) {//NOSONAR
|
||||
// TODO how should this be handled?
|
||||
}
|
||||
else {
|
||||
builder.addEntry(name, node.asText());
|
||||
}
|
||||
builder.addEntry(name, node.asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class JsonStringToTupleConverter implements Converter<String, Tuple> {
|
||||
|
||||
@@ -54,15 +53,7 @@ public class JsonStringToTupleConverter implements Converter<String, Tuple> {
|
||||
builder.addEntry(name, nodeToList(node));
|
||||
}
|
||||
else {
|
||||
if (name.equals("id")) {//NOSONAR
|
||||
// TODO how should this be handled?
|
||||
}
|
||||
else if (name.equals("timestamp")) {//NOSONAR
|
||||
// TODO how should this be handled?
|
||||
}
|
||||
else {
|
||||
builder.addEntry(name, node.asText());
|
||||
}
|
||||
builder.addEntry(name, node.asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import java.util.Locale;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.util.AlternativeJdkIdGenerator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.IdGenerator;
|
||||
|
||||
/**
|
||||
* Builder class to create Tuple instances.
|
||||
@@ -42,7 +40,6 @@ import org.springframework.util.IdGenerator;
|
||||
* @author David Turanski
|
||||
* @author Michael Minella
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
*/
|
||||
public class TupleBuilder {
|
||||
|
||||
@@ -62,8 +59,6 @@ public class TupleBuilder {
|
||||
|
||||
private static Converter<String, Tuple> stringToTupleConverter = new JsonStringToTupleConverter();
|
||||
|
||||
private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator();
|
||||
|
||||
static {
|
||||
defaultConversionService = new DefaultTupleConversionService();
|
||||
defaultConversionService.addConverterFactory(new LocaleAwareStringToNumberConverterFactory(NumberFormat
|
||||
@@ -166,7 +161,7 @@ public class TupleBuilder {
|
||||
protected Tuple newTuple(List<String> names, List<Object> values) {
|
||||
DefaultTuple tuple;
|
||||
|
||||
if(customConversionService != null) {
|
||||
if (customConversionService != null) {
|
||||
tuple = new DefaultTuple(names, values, customConversionService);
|
||||
}
|
||||
else {
|
||||
@@ -200,12 +195,12 @@ public class TupleBuilder {
|
||||
public TupleBuilder setConfigurableConversionService(ConfigurableConversionService formattingConversionService) {
|
||||
Assert.notNull(formattingConversionService);
|
||||
|
||||
if(locale != null) {
|
||||
if (locale != null) {
|
||||
formattingConversionService.addConverterFactory(new LocaleAwareStringToNumberConverterFactory(NumberFormat
|
||||
.getInstance(locale)));
|
||||
}
|
||||
|
||||
if(dateFormat != null) {
|
||||
if (dateFormat != null) {
|
||||
formattingConversionService.addConverter(new StringToDateConverter(dateFormat));
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
*/
|
||||
public class TupleToJsonStringConverter implements Converter<Tuple, String> {
|
||||
|
||||
@@ -47,8 +46,6 @@ public class TupleToJsonStringConverter implements Converter<Tuple, String> {
|
||||
|
||||
private ObjectNode toObjectNode(Tuple source) {
|
||||
ObjectNode root = mapper.createObjectNode();
|
||||
// root.put("id", source.getId().toString());
|
||||
// root.put("timestamp", source.getTimestamp());
|
||||
for (int i = 0; i < source.size(); i++) {
|
||||
Object value = source.getValues().get(i);
|
||||
String name = source.getFieldNames().get(i);
|
||||
|
||||
Reference in New Issue
Block a user