我正在尝试通过使用杰克逊将Label
,Pane
,...之类的javaFx节点另存为json,但是收到了一些错误。
这是我的代码:
public class JSONTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane() ;
Label label = new Label( "Tesssssssssssst") ;
pane.getChildren().add( label) ;
pane.setPrefSize( 500 , 500);
primaryStage.setScene( new Scene( pane));
primaryStage.show();
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(pane);
System.out.println( jsonInString);
}
}
并收到此错误:
java.lang.reflect.InvocationTargetException
Caused by: org.codehaus.jackson.map.JsonMappingException: No serializer found for class javafx.scene.SceneAntialiasing and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: javafx.scene.layout.Pane["scene"]->javafx.scene.Scene["antiAliasing"])
at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52)
at org.codehaus.jackson.map.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:25)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:610)
at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:2575)
at org.codehaus.jackson.map.ObjectMapper.writeValueAsString(ObjectMapper.java:2097)
at sample.json.JSONTest.start(JSONTest.java:30)
请帮助我