List of usage examples for org.springframework.kafka.support.converter ConversionException ConversionException
public ConversionException(String message, Throwable cause)
From source file:org.springframework.kafka.support.converter.StringJsonMessageConverter.java
@Override protected Object convertPayload(Message<?> message) { try {//from w ww . j a va2s .c om return this.objectMapper.writeValueAsString(message.getPayload()); } catch (JsonProcessingException e) { throw new ConversionException("Failed to convert to JSON", e); } }
From source file:org.springframework.kafka.support.converter.StringJsonMessageConverter.java
@Override protected Object extractAndConvertValue(ConsumerRecord<?, ?> record, Type type) { JavaType javaType = TypeFactory.defaultInstance().constructType(type); Object value = record.value(); if (value instanceof String) { try {/*from w w w .ja v a 2s .co m*/ return this.objectMapper.readValue((String) value, javaType); } catch (IOException e) { throw new ConversionException("Failed to convert from JSON", e); } } else if (value instanceof byte[]) { try { return this.objectMapper.readValue((byte[]) value, javaType); } catch (IOException e) { throw new ConversionException("Failed to convert from JSON", e); } } else { throw new IllegalStateException("Only String or byte[] supported"); } }