Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

ObjectMeta MarshalJSON error #261

Open
changyaowei opened this issue Dec 26, 2017 · 0 comments
Open

ObjectMeta MarshalJSON error #261

changyaowei opened this issue Dec 26, 2017 · 0 comments

Comments

@changyaowei
Copy link

When MarshalJSON objectMeta, for CreationTimestamp the json method is


// MarshalJSON implements the json.Marshaler interface.
func (t Time) MarshalJSON() ([]byte, error) {
	if t.IsZero() {
		// Encode unset/nil objects as JSON's "null".
		return []byte("null"), nil
	}

	return json.Marshal(t.UTC().Format(time.RFC3339))
}

it convert time struct to a string ,like

''creationTimestamp":"2017-12-26T09:12:42Z"

But in java ,we just convert to a struct like

"creationTimestamp": {
        "Time": "2017-12-26T09:12:42Z"
      },"

when we UnmarshalJSON from java data to go data ,an error happen ,the error is

 []string: CreationTimestamp: unmarshalerDecoder: parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006", parsing 125 ...9:12:42Z"}... 

So, we suggest to change java method

    /**
     * 
     * 
     * @return
     *     The creationTimestamp
     */
    @JsonProperty("creationTimestamp")
    public Time getCreationTimestamp() {
        return creationTimestamp;
    }

in ObjectMeta class ,change to

    /**
     * 
     * 
     * @return
     *     The creationTimestamp
     */
    @JsonProperty("creationTimestamp")
    public string getCreationTimestamp() {
        return new mapper().writeValueAsString(creationTimestamp);
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant