1 // Copyright 2016 Google LLC
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
24 // JSONFloat64 is a float64 that supports proper unmarshaling of special float
25 // values in JSON, according to
26 // https://developers.google.com/protocol-buffers/docs/proto3#json. Although
27 // that is a proto-to-JSON spec, it applies to all Google APIs.
30 // (https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go) has
31 // similar functionality, but only for direct translation from proto messages
33 type JSONFloat64 float64
35 func (f *JSONFloat64) UnmarshalJSON(data []byte) error {
37 if err := json.Unmarshal(data, &ff); err == nil {
42 if err := json.Unmarshal(data, &s); err == nil {
51 return fmt.Errorf("google.golang.org/api/internal: bad float string %q", s)
56 return errors.New("google.golang.org/api/internal: data not float or string")