Reputation: 13
I am creating an instance of the object mapper.
ObjectMapper objectMapper = new ObjectMapper();
This line gives me the following error:
The constructor ObjectMapper() is undefined
What am I doing wrong? Can you please help me? Thanks in advance.
Upvotes: 1
Views: 3734
Reputation: 157
Check libraries in your class.
If you imported other library having same name by mistake, it will cuases a problem..
import org.elasticsearch.index.mapper.ObjectMapper;
import com.fasterxml.jackson.databind.*;
ObjectMapper objectMapper = new ObjectMapper();
The first line should be deleted in above example.
Upvotes: 1
Reputation: 126
You might be missing the below jar if you are using Jackson
jackson-mapper-asl-1.5.0.jar
Also try importing below package
import com.fasterxml.jackson.databind.*;
Upvotes: 0
Reputation: 31
If you use fasterxml jackson ObjectMapper then there is an empty constructor:
/*
/**********************************************************
/* 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);
}
This is copied from the JavaDoc. Please make sure that the Import statement is correct. I am using
import com.fasterxml.jackson.databind.ObjectMapper;
and it works for me.
Upvotes: 1