Skip to content

json.Marshal/Unmarshal appengine.GeoPoint #75

@cybercent

Description

@cybercent

Hi,

Properties of type appengine.GeoPoint are not marshaled into json. Could marshaling/unmarshaling of appengine.GeoPoint be added to the package ?

Meanwhile, if someone encounters the same issue, here is a workaround:

type GeoPointJson appengine.GeoPoint

func (g *GeoPointJson) UnmarshalJSON(b []byte) (err error) {
	var jm map[string]float64
	if err = json.Unmarshal(b, &jm); err == nil {
		g.Lat = jm["lat"]
		g.Lng = jm["lon"]
	}
	return
}

func (g *GeoPointJson) MarshalJSON() ([]byte, error) {
	jm := make(map[string]float64)
	jm["lat"] = g.Lat
	jm["lon"] = g.Lng
	return json.Marshal(jm)
}

struct MyEntity {
    Location   GeoPointJson `datastore:"location" json:"location"`
}

Edit: It actually works as expected. Will close this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions