完善 jackson 解析时间。
This commit is contained in:
		@@ -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<QWeatherDisasterWarningItem> 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<QWeatherDisasterWarningItem> warning;
 | 
			
		||||
    private QWeatherDisasterWarningRefer        refer;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "refer")
 | 
			
		||||
    private QWeatherDisasterWarningRefer refer;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user