Browse Source

Error log added for serialization and throw exception before serializing other sort objects

pull/329/head
Can Bezmen 5 years ago
parent
commit
0e1a579de5
  1. 15
      spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java

15
spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java

@ -29,7 +29,11 @@ import com.fasterxml.jackson.databind.JsonNode; @@ -29,7 +29,11 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.data.domain.Sort;
/**
@ -39,6 +43,8 @@ import org.springframework.data.domain.Sort; @@ -39,6 +43,8 @@ import org.springframework.data.domain.Sort;
*/
public class SortJsonComponent {
private static final Log LOG = LogFactory.getLog(SortJsonComponent.class);
public static class SortSerializer extends JsonSerializer<Sort> {
@Override
@ -50,7 +56,14 @@ public class SortJsonComponent { @@ -50,7 +56,14 @@ public class SortJsonComponent {
gen.writeObject(v);
}
catch (IOException e) {
e.printStackTrace();
String message = "Couldn't serialize Sort object for " + v;
if (LOG.isErrorEnabled()) {
LOG.error(message, e);
}
else {
throw new ConversionFailedException(TypeDescriptor.valueOf(Sort.class),
TypeDescriptor.valueOf(String.class), v, e);
}
}
});
gen.writeEndArray();

Loading…
Cancel
Save