
Untitled
By: a guest on
Jun 2nd, 2012 | syntax:
None | size: 0.93 KB | hits: 15 | expires: Never
package fr.pilato.test.jackson;
import static org.junit.Assert.*;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig.Feature;
import org.junit.Test;
public class SerializeTest {
@Test
public void test() {
MyClass myClass = new MyClass("test1", MyEnum.ENUM1);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.AUTO_DETECT_FIELDS, false);
mapper.configure(Feature.AUTO_DETECT_GETTERS, false);
mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false);
try {
String result = mapper.writeValueAsString(myClass);
System.out.println(result);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}