Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import class in eclipse's display view

I need to capture an object inside my application to analise its values. So while debbuging, I'm trying to convert it to json using display tab view. But when I've executed the import code, I got an error:

Sintax error on token "import", assert expected.

Here is what I'm trying to execute in display's view:

import org.codehaus.jackson.map.ObjectMapper;
ObjectMapper OBJECT_MAPPER = new ObjectMapper();
OBJECT_MAPPER.writer().withDefaultPrettyPrinter();

String json = OBJECT_MAPPER.writeValueAsString(cart);
System.out.println(json);

Anyone knows how to import this class?

(Actually, I did it. But I would like to have a generic code in order to not have to modify my class code just to capture its json.)

like image 201
Gabriel Santos Carvalho Avatar asked Jul 12 '26 14:07

Gabriel Santos Carvalho


1 Answers

Remove the import. Use FQN (Full qualified name)

org.codehaus.jackson.map.ObjectMapper OBJECT_MAPPER = new ObjectMapper();
OBJECT_MAPPER.writer().withDefaultPrettyPrinter();

String json = OBJECT_MAPPER.writeValueAsString(cart);
System.out.println(json);

It should work

like image 56
Viltér Panitz Avatar answered Jul 14 '26 02:07

Viltér Panitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!