Commit e491cc48008cc2901ed3d3aef098e5bb193741a9

Authored by 王通
1 parent 026fac98

1.BeanUtils.copyProperties使用有误

src/main/java/com/bsth/entity/AlarmData.java
1 package com.bsth.entity; 1 package com.bsth.entity;
2 2
3 import com.bsth.socket.protocol.Message0207; 3 import com.bsth.socket.protocol.Message0207;
  4 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  5 +import com.fasterxml.jackson.databind.ObjectMapper;
4 import org.springframework.beans.BeanUtils; 6 import org.springframework.beans.BeanUtils;
5 7
6 import java.util.ArrayList; 8 import java.util.ArrayList;
@@ -10,6 +12,7 @@ import java.util.List; @@ -10,6 +12,7 @@ import java.util.List;
10 * @author Hill 12 * @author Hill
11 * 报警数据 13 * 报警数据
12 */ 14 */
  15 +@JsonIgnoreProperties(ignoreUnknown = true)
13 public class AlarmData extends Data { 16 public class AlarmData extends Data {
14 17
15 /** 18 /**
@@ -94,7 +97,8 @@ public class AlarmData extends Data { @@ -94,7 +97,8 @@ public class AlarmData extends Data {
94 } 97 }
95 98
96 public AlarmData(Message0207 message0207) { 99 public AlarmData(Message0207 message0207) {
97 - BeanUtils.copyProperties(message0207, this); 100 + AlarmData data = new ObjectMapper().convertValue(message0207, AlarmData.class);
  101 + BeanUtils.copyProperties(data, this);
98 this.maxAlarmLevel &= (short) 0xFF; 102 this.maxAlarmLevel &= (short) 0xFF;
99 this.energyStorageDeviceQuantity &= (short) 0xFF; 103 this.energyStorageDeviceQuantity &= (short) 0xFF;
100 this.electricMotorQuantity &= (short) 0xFF; 104 this.electricMotorQuantity &= (short) 0xFF;
src/main/java/com/bsth/entity/PeakData.java
1 package com.bsth.entity; 1 package com.bsth.entity;
2 2
3 import com.bsth.socket.protocol.Message0206; 3 import com.bsth.socket.protocol.Message0206;
  4 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 import org.springframework.beans.BeanUtils; 5 import org.springframework.beans.BeanUtils;
5 6
6 /** 7 /**
7 * @author Hill 8 * @author Hill
8 * 极值数据 9 * 极值数据
9 */ 10 */
  11 +@JsonIgnoreProperties(ignoreUnknown = true)
10 public class PeakData extends Data { 12 public class PeakData extends Data {
11 13
12 /** 14 /**
@@ -102,7 +104,8 @@ public class PeakData extends Data { @@ -102,7 +104,8 @@ public class PeakData extends Data {
102 } 104 }
103 105
104 public PeakData(Message0206 message0206) { 106 public PeakData(Message0206 message0206) {
105 - BeanUtils.copyProperties(message0206, this); 107 + PeakData data = new PeakData();
  108 + BeanUtils.copyProperties(data, this);
106 this.maxVoltageSubSysCode &= (short) 0xFF; 109 this.maxVoltageSubSysCode &= (short) 0xFF;
107 this.maxVoltageSubCode &= (short) 0xFF; 110 this.maxVoltageSubCode &= (short) 0xFF;
108 this.minVoltageSubSysCode &= (short) 0xFF; 111 this.minVoltageSubSysCode &= (short) 0xFF;
src/main/java/com/bsth/entity/VehicleData.java
@@ -2,6 +2,7 @@ package com.bsth.entity; @@ -2,6 +2,7 @@ package com.bsth.entity;
2 2
3 import com.bsth.socket.protocol.Message0201; 3 import com.bsth.socket.protocol.Message0201;
4 import com.fasterxml.jackson.annotation.JsonIgnore; 4 import com.fasterxml.jackson.annotation.JsonIgnore;
  5 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 import com.fasterxml.jackson.annotation.JsonProperty; 6 import com.fasterxml.jackson.annotation.JsonProperty;
6 import org.springframework.beans.BeanUtils; 7 import org.springframework.beans.BeanUtils;
7 8
@@ -9,6 +10,7 @@ import org.springframework.beans.BeanUtils; @@ -9,6 +10,7 @@ import org.springframework.beans.BeanUtils;
9 * @author Hill 10 * @author Hill
10 * 整车数据 11 * 整车数据
11 */ 12 */
  13 +@JsonIgnoreProperties(ignoreUnknown = true)
12 public class VehicleData extends Data { 14 public class VehicleData extends Data {
13 15
14 /** 16 /**
@@ -140,7 +142,8 @@ public class VehicleData extends Data { @@ -140,7 +142,8 @@ public class VehicleData extends Data {
140 } 142 }
141 143
142 public VehicleData(Message0201 message0201) { 144 public VehicleData(Message0201 message0201) {
143 - BeanUtils.copyProperties(message0201, this); 145 + VehicleData data = new VehicleData();
  146 + BeanUtils.copyProperties(data, this);
144 this.drivingForce = (gear & 32) == 32 ? true : false; 147 this.drivingForce = (gear & 32) == 32 ? true : false;
145 this.brakingForce = (gear & 16) == 16 ? true : false; 148 this.brakingForce = (gear & 16) == 16 ? true : false;
146 this.gear1 = (byte) (gear & 15); 149 this.gear1 = (byte) (gear & 15);