Yelp / parcelgen

Helpful tool to make data objects easier for Android
Other
65 stars 35 forks source link

Define default values #1

Closed lxdvs closed 13 years ago

lxdvs commented 13 years ago

Right now I believe the parser will default to defaulting to 0 when parsing nonexistent keys with optInt and optLong; it would be better if long and int parsing defaulted to -1. Double parsing already correctly defaults to NaN.

However, the best option would be if the fallback value were definable in the json.

Pretz commented 13 years ago

Sounds like a good idea. How do you think it should be specified? A "defaults" property to value dict? Or should it be part of props?

    "props": {
        "int": ["reviewCount"],
        "double": ["distance"],
        "Location": ["location"] 
    },
    "defaults": {
        "reviewCount": -1
    }

vs

    "props": {
        "int": [["reviewCount", -1]],
        "double": ["distance"],
        "Location": ["location"] 
    }
lxdvs commented 13 years ago

I think a separate defaults section sticks to your basic theme of fields-in-blocks (similar to json_map or serializables).