Preparations to switch to jackson library
This commit is contained in:
@ -25,7 +25,14 @@
|
||||
*/
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import java.awt.Dialog;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.InputVerifier;
|
||||
import javax.swing.JComponent;
|
||||
@ -40,6 +47,7 @@ import opensesim.util.IDGenerator.Id;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
@ -53,6 +61,7 @@ public class AssetEditorDialog extends EscDialog {
|
||||
* Creates new form CreateAssetDialog
|
||||
*/
|
||||
public AssetEditorDialog(Dialog parent, AbstractAsset asset) {
|
||||
|
||||
super(parent, true);
|
||||
initComponents();
|
||||
world = Globals.world;
|
||||
@ -131,7 +140,6 @@ public class AssetEditorDialog extends EscDialog {
|
||||
int selected = this.assetEditorPanel.assetTypesComboBox.getSelectedIndex();
|
||||
Class<AbstractAsset> cls = (Class<AbstractAsset>) this.assetEditorPanel.asset_types.get(selected);
|
||||
asset = AbstractAsset.create(world, cls, assetEditorPanel.symField.getText());
|
||||
|
||||
|
||||
//new BasicAsset(assetEditor.symField.getText());
|
||||
// newId = BasicAsset.newAssed(asset);
|
||||
@ -189,6 +197,23 @@ public class AssetEditorDialog extends EscDialog {
|
||||
dialog.setLocationRelativeTo(parent);
|
||||
dialog.setVisible(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// disable auto detection
|
||||
mapper.disable(MapperFeature.AUTO_DETECT_CREATORS,
|
||||
MapperFeature.AUTO_DETECT_FIELDS,
|
||||
MapperFeature.AUTO_DETECT_GETTERS,
|
||||
MapperFeature.AUTO_DETECT_IS_GETTERS);
|
||||
// if you want to prevent an exception when classes have no annotated properties
|
||||
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||
|
||||
String vs;
|
||||
try {
|
||||
vs = mapper.writeValueAsString(dialog.assetEditorPanel);
|
||||
System.out.print(vs);
|
||||
} catch (JsonProcessingException ex) {
|
||||
Logger.getLogger(AssetEditorDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return dialog.newId;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
@ -35,6 +36,7 @@ import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import opensesim.AbstractAsset;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.JTextFieldLimit;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -50,7 +52,6 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
public AssetEditorPanel() {
|
||||
super();
|
||||
asset_types = Globals.getAvailableAssetsTypes();
|
||||
|
||||
asset_types.sort(new Comparator<Class<AbstractAsset>>() {
|
||||
@Override
|
||||
public int compare(Class<AbstractAsset> o1, Class<AbstractAsset> o2) {
|
||||
@ -84,6 +85,17 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
symField.setText(asset.getSymbol());
|
||||
nameField.setText(asset.getName());
|
||||
decimalsField.getModel().setValue(asset.getDecimals());
|
||||
|
||||
}
|
||||
|
||||
@JsonGetter("name")
|
||||
public String getNameField() {
|
||||
return nameField.getText();
|
||||
}
|
||||
@JsonGetter("sym")
|
||||
public String getSymField() {
|
||||
return symField.getText();
|
||||
}
|
||||
|
||||
public JDialog dialog;
|
||||
|
Reference in New Issue
Block a user