jsonobject getString() behavior in v4

103 views
Skip to first unread message

Asher Tarnopolski

unread,
Mar 11, 2021, 2:20:48 AM3/11/21
to vert.x
hi,
i see that JsonObject.getString() in 4.0.2 and does a toString() on whatever value is present instead of  throwing a ClassCastException in case the values isn't actually a string. is this indeed a desired behavior? 
cheers

Paulo Lopes

unread,
Mar 11, 2021, 3:24:19 AM3/11/21
to vert.x

Hi,

Yes, that was a long discussion during the 4.0 development cycle. The reason for this was to ensure that the toString() adheres more close to the JVM API contract. You can call a toString() on any object and get it’s representation, so the JsonObject/JsonArray now also follow that agreement.

Asher Tarnopolski

unread,
Mar 11, 2021, 3:47:24 AM3/11/21
to vert.x
thanks . this just sounds a bit strange to me, consider the case when a consumer expects to receive a string, but a producer sends a json array. one would expect this to fail in communication/protocol parsing layer and not being propagated as a valid input into the business logic. of course this can be worked around using getValue and a cast, it's just strange that getString doesn't behave the way other getWhatever do.

Asher Tarnopolski

unread,
Mar 25, 2021, 11:10:44 AM3/25/21
to vert.x
now i also see that JsonArray of enums stream() emits strings and loses the enum type of the values. is this related? 

Paulo Lopes

unread,
Mar 26, 2021, 9:33:37 AM3/26/21
to vert.x
Hi,

Can you give an example, perhaps it could be a bug as Enums are allowed unless explicitly converted their original value should be preserved.

Asher Tarnopolski

unread,
Mar 26, 2021, 9:43:18 AM3/26/21
to vert.x
thanks, paulo.
i've opened a bug with an example here: https://github.com/eclipse-vertx/vert.x/issues/3873
it seems julien has already picked it for 4.0.4 fixes.
cheers.

Reply all
Reply to author
Forward
0 new messages