Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为SerializationFeature.INDENT\u输出配置jackson映射器对象时出错_Java_Json_Jackson - Fatal编程技术网

Java 为SerializationFeature.INDENT\u输出配置jackson映射器对象时出错

Java 为SerializationFeature.INDENT\u输出配置jackson映射器对象时出错,java,json,jackson,Java,Json,Jackson,我正在尝试将我创建的名为User的域对象序列化为json文件 ObjectMapper mapper = new ObjectMapper(); List<User> users = new ArrayList<User>(); users.add(user1); users.add(user2); users.add(user3); mapper.writeValue(file, users); 我在eclipse编译器中

我正在尝试将我创建的名为User的域对象序列化为json文件

ObjectMapper mapper = new ObjectMapper();
List<User> users = new ArrayList<User>();

    users.add(user1);
    users.add(user2);
    users.add(user3);

mapper.writeValue(file, users);         
我在eclipse编译器中得到的错误如下:

类型中的方法configure(SerializationConfig.Feature,boolean) ObjectMapper不适用于参数 (序列化功能,布尔值)

这是怎么回事?我错过了什么明显的东西吗?其工作原理与文档中所示不符。
提前谢谢。

您的类路径1.x和2.x上似乎有两个版本的
Jackson
,您正在混合这两个版本。您的
ObjectMapper
似乎来自1.x,您正试图从2.x版本传递
SerializationFeature

因此,您要么必须使用
com.fasterxml.jackson.databind.ObjectMapper
(2.x),要么必须将
SerializationConfig.Feature
传递给方法
configure


有关更改,请参见。

您可能拥有来自
com.fasterxml.jackson.databind.ObjectMapper
org.codehaus.jackson.map.ObjectMapper

//com.fasterxml.jackson.databind.ObjectMapper can be used like this,
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
ObjectMapper mapper = new ObjectMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

//org.codehaus.jackson.map.ObjectMappe can be used like this,
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
ObjectMapper mapper = new ObjectMapper()
mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
希望这会有帮助

//com.fasterxml.jackson.databind.ObjectMapper can be used like this,
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
ObjectMapper mapper = new ObjectMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

//org.codehaus.jackson.map.ObjectMappe can be used like this,
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
ObjectMapper mapper = new ObjectMapper()
mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);