无法在 java 中创建 objectMapper
can't create an objectMapper in java
我正在创建对象映射器的实例。
ObjectMapper objectMapper = new ObjectMapper();
这一行给我以下错误:
The constructor ObjectMapper() is undefined
我做错了什么?你能帮我么?提前致谢。
如果您使用 Jackson,您可能会缺少以下 jar
jackson-mapper-asl-1.5.0.jar
也尝试导入下面的包
import com.fasterxml.jackson.databind.*;
如果您使用 fasterxml jackson ObjectMapper,则构造函数为空:
/*
/**********************************************************
/* Life-cycle: constructing instance
/**********************************************************
*/
/**
* Default constructor, which will construct the default
* {@link JsonFactory} as necessary, use
* {@link SerializerProvider} as its
* {@link SerializerProvider}, and
* {@link BeanSerializerFactory} as its
* {@link SerializerFactory}.
* This means that it
* can serialize all standard JDK types, as well as regular
* Java Beans (based on method names and Jackson-specific annotations),
* but does not support JAXB annotations.
*/
public ObjectMapper() {
this(null, null, null);
}
这是从 JavaDoc 复制的。请确保导入语句正确。我正在使用
import com.fasterxml.jackson.databind.ObjectMapper;
它对我有用。
检查您 class 中的库。
如果您错误地导入了同名的其他库,则会出现问题..
import org.elasticsearch.index.mapper.ObjectMapper;
import com.fasterxml.jackson.databind.*;
ObjectMapper objectMapper = new ObjectMapper();
在上面的例子中,第一行应该被删除。
我正在创建对象映射器的实例。
ObjectMapper objectMapper = new ObjectMapper();
这一行给我以下错误:
The constructor ObjectMapper() is undefined
我做错了什么?你能帮我么?提前致谢。
如果您使用 Jackson,您可能会缺少以下 jar
jackson-mapper-asl-1.5.0.jar
也尝试导入下面的包
import com.fasterxml.jackson.databind.*;
如果您使用 fasterxml jackson ObjectMapper,则构造函数为空:
/*
/**********************************************************
/* Life-cycle: constructing instance
/**********************************************************
*/
/**
* Default constructor, which will construct the default
* {@link JsonFactory} as necessary, use
* {@link SerializerProvider} as its
* {@link SerializerProvider}, and
* {@link BeanSerializerFactory} as its
* {@link SerializerFactory}.
* This means that it
* can serialize all standard JDK types, as well as regular
* Java Beans (based on method names and Jackson-specific annotations),
* but does not support JAXB annotations.
*/
public ObjectMapper() {
this(null, null, null);
}
这是从 JavaDoc 复制的。请确保导入语句正确。我正在使用
import com.fasterxml.jackson.databind.ObjectMapper;
它对我有用。
检查您 class 中的库。
如果您错误地导入了同名的其他库,则会出现问题..
import org.elasticsearch.index.mapper.ObjectMapper;
import com.fasterxml.jackson.databind.*;
ObjectMapper objectMapper = new ObjectMapper();
在上面的例子中,第一行应该被删除。