Commit e491cc48008cc2901ed3d3aef098e5bb193741a9

Authored by 王通
1 parent 026fac98

1.BeanUtils.copyProperties使用有误

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