Spring XML - 没有String-argument构造函数/工厂方法从String值反序列化

时间:2017-09-25 10:32:49

标签: java xml spring

我在尝试从Spring RestController反序列化某些XML时遇到此错误。

10:32:20.275 [main] WARN  org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of com.example.SomeThing: no String-argument constructor/factory method to deserialize from String value ('AAAA')

这是类(更改名称和包)

public final class SomeThing{
    public static final SomeThing AAAA = create("AAAA");

    public static SomeThing create(final String value) {
      SomeThing result = new SomeThing ();
      result.setValue(value);
      return result;
    }
}

那么如何更改此类以便能够反序列化?

1 个答案:

答案 0 :(得分:1)

您应该将let store = createStore( // your reducers here... // ... applyMiddleware(socketMiddleware) // our web socket middleware ) // the callback will invoked only if the connection was successful // the React-Dom's render function is our callback in this case socketStart(store, () => { render(<App />, document.getElementById("root")); }); 方法标记为 工厂方法 ,以便将其解析为实例化新Something#create实例的方法。

以下是您的类的修改版本(请注意,它已被更改以匹配主OP中的声明字段):

Something