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

ObjectMeta MarshalJSON error #261

Description

@changyaowei

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions