[Info-vax] Simple Pascal question

Arne Vajhøj arne at vajhoej.dk
Thu Sep 5 13:30:50 EDT 2024


On 8/9/2024 8:47 AM, Simon Clubley wrote:
> On 2024-08-08, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> On 8/8/2024 8:13 AM, Simon Clubley wrote:
>>> On 2024-08-07, Arne Vajhøj <arne at vajhoej.dk> wrote:
>>>> On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
>>>>> Dates/times? You have to contend with an API that has accumulated so much
>>>>> legacy cruft, that you are left with an old class where every single
>>>>> member is deprecated, yet the class itself is still needed in the newer-
>>>>> style calls.
>>>>
>>>> That is also one of Roland's pet peeves.
>>>
>>> Now try parsing JSON using the supplied builtin Java libraries
>>> on Android. :-)
>>>
>>> There is a solution but it is not as clean as elsewhere.
>>
>> I would use binding instead of parsing.
>>
>> I have never done anything on Android, but I would
>> expect both JSON-B and Jackson to work on Android
> 
> I like to avoid using third-party libraries when possible.

You will have to evaluate benefits vs added size and management.

>> JSON-B is:
>>
>> Jsonb b = JsonbBuilder.create();
>> X o = b.fromJson(jsonstr, X.class);
>>
>> Jackson is:
>>
>> ObjectMapper om = new ObjectMapper();
>> X o = om.readValue(jsonstr, X.class);
>>
>> It don't get much easier than that.

I would probably have listed GSON as well:

Gson gson = new Gson();
X o = gson.fromJson(jsonstr, X.class);

GSON is Google.

But apparently a different team in Google than the one
that does Android.

> For comparison, here are the two built-in options available on Android
> that I know about:
> 
> https://developer.android.com/reference/android/util/JsonReader
> https://developer.android.com/reference/org/json/package-summary

There are 4 types of API's for this:
1) Tree
2) Class binding
3) Streaming
    A) Pull
    B) Push

android.util.JsonReader is a 3A.

org.json.* is a 1.

Given that:
* 1 is cumbersome
* 2 is what you want
* 3A is a PITA
* 3B is a huge PITA

Then I suggest you bite the bullet and go for an external library
that supports class binding.

GSON is less than 300 KB. From Google. Widely used (Maven lists over
23000 other software depending on it) so not likely to go away.

Arne



More information about the Info-vax mailing list