org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type:

后端 未结 2 432
醉话见心
醉话见心 2021-01-23 09:40

I have multipart file in the first place and I want to send it to camel pipeline and save this file with original name.

my code:

@Autowired
ProducerTempl         


        
2条回答
  •  难免孤独
    2021-01-23 10:36

    An example of a type converter using SpringBoot which will be automatically picked up using Camel 2.23.0 or later.

    @Component
    public class MyPackageTypeConverter implements TypeConverters {
    
      private final ObjectMapper mapper;
    
      @Autowired
      public MyPackageTypeConverter(ObjectMapper mapper) {
        this.mapper = mapper;
      }
    
      @Converter
      public byte[] myPackageToByteArray(MyPackage source) {
        try {
          return mapper.writeValueAsBytes(source);
        } catch (JsonProcessingException e) {
          throw new RuntimeException(e);
        }
      }
    
      @Converter
      public MyPackage byteArrayToMyPackage(byte[] source) {
        try {
          return mapper.readValue(source, MyPackage.class);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    
    }
    

提交回复
热议问题