Phate
Phate

Reputation: 6612

Jackson failing displaying empty array: null inside ([null] )

I have this class:

public class MyClass {
public String methodName;
public Object[] argument;

public MyClass(String m,Object[]){...

I want to send an empty argument array :

ObjectMapper mapper = new ObjectMapper();
MyClass cls = new MyClass("list_dbs",new Object[1]);
mapper.writeValue(System.out, req);

I get:

{"methodName":"list_dbs","argument":[null]}

Why is there that "null" ?

Upvotes: 1

Views: 374

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280011

Because you created your array

MyClass cls = new MyClass("list_dbs",new Object[1]);

with one element.

So the Object[] is

[0] = null

If you want an empty array, ie. one without elements, you need

MyClass cls = new MyClass("list_dbs",new Object[0]);

Upvotes: 6

Related Questions