TestJacksonMapping.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import com.fasterxml.jackson.databind.ObjectMapper;
  2. public class TestJacksonMapping {
  3. public static void main(String[] args) {
  4. try {
  5. String json = "{\"id\": 111, \"coordinates\": \"119.14413000000002,25.867905,-1.165372999387529\", \"rotationX\": 0, \"rotationY\": 0, \"rotationZ\": 260, \"scaleX\": 1, \"scaleY\": 1, \"scaleZ\": 1}";
  6. ObjectMapper mapper = new ObjectMapper();
  7. TestModel model = mapper.readValue(json, TestModel.class);
  8. System.out.println("=== 反序列化结果 ===");
  9. System.out.println("modelId: " + model.getModelId());
  10. System.out.println("modelCoordinates: " + model.getModelCoordinates());
  11. System.out.println("rotationX: " + model.getRotationX());
  12. System.out.println("rotationY: " + model.getRotationY());
  13. System.out.println("rotationZ: " + model.getRotationZ());
  14. System.out.println("scaleX: " + model.getScaleX());
  15. System.out.println("scaleY: " + model.getScaleY());
  16. System.out.println("scaleZ: " + model.getScaleZ());
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. static class TestModel {
  22. private Long modelId;
  23. private String modelCoordinates;
  24. private Double rotationX;
  25. private Double rotationY;
  26. private Double rotationZ;
  27. private Double scaleX;
  28. private Double scaleY;
  29. private Double scaleZ;
  30. public Long getModelId() {
  31. return modelId;
  32. }
  33. public void setId(Long id) {
  34. this.modelId = id;
  35. }
  36. public String getModelCoordinates() {
  37. return modelCoordinates;
  38. }
  39. public void setCoordinates(String coordinates) {
  40. this.modelCoordinates = coordinates;
  41. }
  42. public Double getRotationX() {
  43. return rotationX;
  44. }
  45. public void setRotationX(Double rotationX) {
  46. this.rotationX = rotationX;
  47. }
  48. public Double getRotationY() {
  49. return rotationY;
  50. }
  51. public void setRotationY(Double rotationY) {
  52. this.rotationY = rotationY;
  53. }
  54. public Double getRotationZ() {
  55. return rotationZ;
  56. }
  57. public void setRotationZ(Double rotationZ) {
  58. this.rotationZ = rotationZ;
  59. }
  60. public Double getScaleX() {
  61. return scaleX;
  62. }
  63. public void setScaleX(Double scaleX) {
  64. this.scaleX = scaleX;
  65. }
  66. public Double getScaleY() {
  67. return scaleY;
  68. }
  69. public void setScaleY(Double scaleY) {
  70. this.scaleY = scaleY;
  71. }
  72. public Double getScaleZ() {
  73. return scaleZ;
  74. }
  75. public void setScaleZ(Double scaleZ) {
  76. this.scaleZ = scaleZ;
  77. }
  78. }
  79. }