From 07ae9f88a3de59b979b3d8afae55e1ebb8d3a48a Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Sun, 24 Apr 2022 11:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20jackson=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disaster/QWeatherDisasterWarning.java | 51 ++++++----- .../disaster/QWeatherDisasterWarningItem.java | 87 ++++++++----------- .../officalAccount/sendMessageTest.java | 6 +- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java index e527a88..ec911b6 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java @@ -1,23 +1,24 @@ +/* + * @Author: Kane + * @Date: 2022-04-24 10:21:46 + * @LastEditors: Kane + * @LastEditTime: 2022-04-24 11:28:58 + * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\notify\disaster\QWeatherDisasterWarning.java + * @Description: + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ package com.cpic.xim.notify.disaster; +import java.util.Date; import java.util.Vector; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; public class QWeatherDisasterWarning { - public QWeatherDisasterWarning( String code, - String updateTime, - String fxLink, - Vector warning, - QWeatherDisasterWarningRefer refer ) - { - this.code = code; - this.updateTime = updateTime; - this.fxLink = fxLink; - this.warning = warning; - this.refer = refer; - } - - public QWeatherDisasterWarning() {} + public QWeatherDisasterWarning() + {} public String getCode() { @@ -29,12 +30,12 @@ public class QWeatherDisasterWarning this.code = code; } - public String getUpdateTime() + public Date getUpdateTime() { return updateTime; } - public void setUpdateTime( String updateTime ) + public void setUpdateTime( Date updateTime ) { this.updateTime = updateTime; } @@ -69,9 +70,19 @@ public class QWeatherDisasterWarning this.refer = refer; } - private String code; - private String updateTime; - private String fxLink; + @JsonProperty( "code") + private String code; + + @JsonProperty( "updateTime") + @JsonFormat( pattern = "yyyy-MM-dd\'T\'HH:mmXXX") + private Date updateTime; + + @JsonProperty( "fxLink") + private String fxLink; + + @JsonProperty( "warning") private Vector warning; - private QWeatherDisasterWarningRefer refer; + + @JsonProperty( "refer") + private QWeatherDisasterWarningRefer refer; } diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java index ad4ba37..53397ea 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java @@ -1,79 +1,61 @@ package com.cpic.xim.notify.disaster; +import java.util.Date; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; //import com.fasterxml.jackson.annotation.JsonIgnore; public class QWeatherDisasterWarningItem { - public QWeatherDisasterWarningItem() {} - public QWeatherDisasterWarningItem( String id, - String sender, - String pubTime, - String title, - String status, - String level, - String type, - String typeName, - String text, - String related, - String urgency, String certainty ) + public QWeatherDisasterWarningItem() + {} + + public QWeatherDisasterWarningItem( String id, String sender, Date pubTime, String title, + String status, String level, String type, String typeName, String text, String related, + String urgency, String certainty) { - this.id = id; - this.sender = sender; - this.pubTime = pubTime; - this.title = title; - this.status = status; - this.level = level; - this.type = type; + this.id = id; + this.sender = sender; + this.pubTime = pubTime; + this.title = title; + this.status = status; + this.level = level; + this.type = type; this.typeName = typeName; - this.text = text; - this.related = related; - this.urgency = urgency; + this.text = text; + this.related = related; + this.urgency = urgency; this.certainty = certainty; } @Override public boolean equals( Object o ) { - if ( this == o ) + if ( this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) + if ( o == null || getClass() != o.getClass()) { return false; } QWeatherDisasterWarningItem that = (QWeatherDisasterWarningItem) o; - return id.equals( that.id ) && Objects.equals( sender, that.sender ) && Objects.equals( pubTime, - that.pubTime ) && Objects.equals( - title, - that.title ) && Objects.equals( status, that.status ) && Objects.equals( level, - that.level ) && Objects.equals( - type, - that.type ) && Objects.equals( typeName, that.typeName ) && Objects.equals( text, - that.text ) && Objects.equals( - related, - that.related ) && Objects.equals( urgency, that.urgency ) && Objects.equals( certainty, - that.certainty ); + return id.equals( that.id ) && Objects.equals( sender, that.sender ) + && Objects.equals( pubTime, that.pubTime ) && Objects.equals( title, that.title ) + && Objects.equals( status, that.status ) && Objects.equals( level, that.level ) + && Objects.equals( type, that.type ) && Objects.equals( typeName, that.typeName ) + && Objects.equals( text, that.text ) && Objects.equals( related, that.related ) + && Objects.equals( urgency, that.urgency ) + && Objects.equals( certainty, that.certainty ); } @Override public int hashCode() { - return Objects.hash( id, - sender, - pubTime, - title, - status, - level, - type, - typeName, - text, - related, - urgency, - certainty ); + return Objects.hash( id, sender, pubTime, title, status, level, type, typeName, text, + related, urgency, certainty ); } public String getId() @@ -96,12 +78,12 @@ public class QWeatherDisasterWarningItem this.sender = sender; } - public String getPubTime() + public Date getPubTime() { return pubTime; } - public void setPubTime( String pubTime ) + public void setPubTime( Date pubTime ) { this.pubTime = pubTime; } @@ -198,8 +180,11 @@ public class QWeatherDisasterWarningItem private String id; private String sender; - @JsonFormat(pattern="yyyy-MM-dd'T'HH:mm") - private String pubTime; + + @JsonProperty( "pubTime") + @JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX") + private Date pubTime; + private String title; private String status; private String level; diff --git a/code/java/DisasterWarning/src/test/java/com/cpic/xim/wechat/officalAccount/sendMessageTest.java b/code/java/DisasterWarning/src/test/java/com/cpic/xim/wechat/officalAccount/sendMessageTest.java index 2cda05e..695247d 100644 --- a/code/java/DisasterWarning/src/test/java/com/cpic/xim/wechat/officalAccount/sendMessageTest.java +++ b/code/java/DisasterWarning/src/test/java/com/cpic/xim/wechat/officalAccount/sendMessageTest.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-04-22 10:53:49 * @LastEditors: Kane - * @LastEditTime: 2022-04-23 23:44:54 + * @LastEditTime: 2022-04-24 11:31:50 * @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java * @Description: * @@ -16,6 +16,7 @@ import org.junit.Test; import static org.junit.Assert.*; import com.cpic.xim.httpUtil.*; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.*; import com.fasterxml.jackson.databind.ObjectMapper; @@ -72,6 +73,9 @@ public class sendMessageTest QWeatherDisasterWarning warning = mapper.readValue( warningJSON, QWeatherDisasterWarning.class ); + SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm" ); + String putTime = format.format( warning.getUpdateTime() ); + sendMessage.sendWeatherDisasterWarning( url, warning ); } catch (Exception error)