首页 > 解决方案 > 我正在从一项服务连接到另一个面临的转换问题

问题描述

我的代码:

final MultiValueMap<String, String> parts = new LinkedMultiValueMap<String, String>();
        parts.add( "fileName", fileName );
        
        HttpHeaders xmlHeaders = new HttpHeaders();
        xmlHeaders.setContentType( MediaType.APPLICATION_XML );
        
        HttpEntity<Resource> xmlEntity = new HttpEntity<Resource>( new FileSystemResource( file ), xmlHeaders );
        parts.add( "file", xmlEntity );
        
        final String url = baseurl+url;
        
        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( parts, createHttpHeadersWithToken() );
        
 String response= restTemplate.exchange( url, HttpMethod.POST, requestEntity, String.class );

例外

调用后配置文件时发生异常:{} org.springframework.http.converter.HttpMessageConversionException:类型定义错误:[简单类型,类 java.nio.channels.Channels$1];嵌套异常是 com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.nio.channels.Channels$1 and no properties found to create BeanSerializer(为避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链: org.springframework.util.LinkedMultiValueMap["file"]->java.util.LinkedList[0]->org.springframework.http.HttpEntity["body"]->org.springframework.core.io.FileSystemResource["outputStream "])

标签: javaspring

解决方案


推荐阅读