forest icon indicating copy to clipboard operation
forest copied to clipboard

关于使用 form-data 类型时,`OkHttp3BodyBuilder#addMultipart` 的一些疑问

Open bengbengbalabalabeng opened this issue 1 year ago • 0 comments

版本:1.5.28

个人示例

public class User {
     private String name;

    public String toString() {
         return "User{name: " + name + "}";
    }
}

public class TestClient {
     
     @PostMapping
     void test(@Body User user, @DataFile File file);

}

OkHttp3BodyBuilder#addMultipart(MultipartBody.Builder, String, Object, String, Charset, ForestJsonConverter) 方法实现中,对 value 的操作如下:

MappingTemplate.getParameterValue(jsonConverter, value);

该实现只会对 MapCollection 进行 jsonConverter.encodeToString() 序列化,对其它 Object 都直接以 toString() ,这时在我的示例中 user Part 内容就直接显示的是 toString() 的结果(预期:显示 User 对象的 Json 字符串)。问题是为什么不能让我自定义的类也走 jsonConverter.encodeToString() 序列化。而不是修改 test() 方法的 user 参数为字符串类型,自己先把参数序列化好再传入?是跟 Java 原生类不好区分吗,亦或是其它原因?

bengbengbalabalabeng avatar Oct 10 '23 14:10 bengbengbalabalabeng