K
K
ksimmi2021-06-23 12:25:01
JSON
ksimmi, 2021-06-23 12:25:01

How to describe data types using JSON?

Hello.

There are several services written in different languages: Java, Ruby. Interservice communication occurs through Kafka, HTTP and DB. In the case of HTTP and DB, the transfer format is JSON and this sometimes leads to problems because different languages ​​and their libraries serialize/deserialize their data types to/from JSON in different ways. Ruby, when serializing to JSON, casts Decimal to a string by wrapping the value with a quote. But Java serializes Decimal to JSON, in fact, as a number, i.e. without quotes. Example.

Ruby: Decimal->JSON = "1.0"
Java: Decimal->JSON = 1.0

All this leads to problems when JSON was serialized by one PL and deserialized by another.

It seems to me that there are two ways out of the situation:
1 abandon JSON in favor of another text format that supports types, but I don't know anything other than XML and XML for sure;
2 enrich JSON with additional meta-data about their types. I thought about JSON Schema, but there are also Cons. Firstly, it is too cumbersome, and secondly, I never saw the Decimal type there, they squeak on the Internet about some kind of multipleOf-type, but I did not like the idea.

Please suggest a solution.

Thank you.

UPD.

I know about protobuff, I used it. He could have saved us, but that's not an option right now. The fact is that historically we have a bunch of old java services supported by 5 java commands that don’t want to use anything other than HTTP, these services have a completely synchronous interaction. Also recently there are about 18 ruby ​​services, they are completely asynchronous, do not use HTTP, only kafka. Once upon a time, a protobuff was planned, but so far it has been possible to do without it. For the interaction of Java and Ruby services via HTTP, on the Ruby side, an interlayer service, a regular web server, was raised.

The problem in general is that other teams don't want either protobuff or Kafka.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2021-06-23
@d-stream

Well, in general, google protobuf is often used for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question