@@ -63,3 +63,97 @@ func TestItemMarshal(t *testing.T) {
63
63
64
64
assert .JSONEq (t , expected , string (data ))
65
65
}
66
+
67
+ func TestItemUnmarshal (t * testing.T ) {
68
+ data := `{
69
+ "type": "Feature",
70
+ "stac_version": "1.0.0",
71
+ "id": "item-id",
72
+ "geometry": {
73
+ "type": "Point",
74
+ "coordinates": [1, 2]
75
+ },
76
+ "properties": {
77
+ "test": "value"
78
+ },
79
+ "links": [
80
+ {
81
+ "rel": "self",
82
+ "href": "https://example.com/stac/item-id"
83
+ }
84
+ ],
85
+ "assets": {
86
+ "thumbnail": {
87
+ "title": "Thumbnail",
88
+ "href": "https://example.com/stac/item-id/thumb.png",
89
+ "type": "image/png"
90
+ }
91
+ }
92
+ }`
93
+
94
+ item := & stac.Item {}
95
+ require .NoError (t , json .Unmarshal ([]byte (data ), item ))
96
+
97
+ assert .Equal (t , "item-id" , item .Id )
98
+
99
+ require .NotNil (t , item .Geometry )
100
+
101
+ g , ok := item .Geometry .(map [string ]any )
102
+ require .True (t , ok )
103
+ geometryType , ok := g ["type" ].(string )
104
+ require .True (t , ok )
105
+ assert .Equal (t , "Point" , geometryType )
106
+ }
107
+
108
+ type TestGeometry struct {
109
+ data []byte
110
+ }
111
+
112
+ func (g * TestGeometry ) UnmarshalJSON (data []byte ) error {
113
+ g .data = data
114
+ return nil
115
+ }
116
+
117
+ func TestGeometryUnmarshal (t * testing.T ) {
118
+ original := & TestGeometry {}
119
+ stac .GeometryUnmarshaler (original )
120
+ defer stac .GeometryUnmarshaler (nil )
121
+
122
+ data := `{
123
+ "type": "Feature",
124
+ "stac_version": "1.0.0",
125
+ "id": "item-id",
126
+ "geometry": {
127
+ "type": "Point",
128
+ "coordinates": [1, 2]
129
+ },
130
+ "properties": {
131
+ "test": "value"
132
+ },
133
+ "links": [
134
+ {
135
+ "rel": "self",
136
+ "href": "https://example.com/stac/item-id"
137
+ }
138
+ ],
139
+ "assets": {
140
+ "thumbnail": {
141
+ "title": "Thumbnail",
142
+ "href": "https://example.com/stac/item-id/thumb.png",
143
+ "type": "image/png"
144
+ }
145
+ }
146
+ }`
147
+
148
+ item := & stac.Item {}
149
+ require .NoError (t , json .Unmarshal ([]byte (data ), item ))
150
+
151
+ assert .Equal (t , "item-id" , item .Id )
152
+
153
+ assert .Nil (t , original .data )
154
+ require .NotNil (t , item .Geometry )
155
+
156
+ g , ok := item .Geometry .(* TestGeometry )
157
+ require .True (t , ok )
158
+ assert .NotNil (t , g .data )
159
+ }
0 commit comments