[英]Jersey client side receive pojo us bytes
small question, but I can't find an answer on the internet... or I just don't know where to search. 小问题,但是我无法在互联网上找到答案...或者我只是不知道在哪里搜索。 Is there any possibility to have a Restful method (Java EE) that returns back to the client a POJO serialized us bytes (using ByteArrayOutputStream, FlatBuffers or some other library). 是否有可能有一种Restful方法(Java EE),该方法将POJO序列化的我们的字节返回给客户端(使用ByteArrayOutputStream,FlatBuffers或某些其他库)。 And the client to cast the bytes back to a POJO object by using jquery or javascript in general ( us client side )? 客户端一般通过使用jquery或javascript将字节转换为POJO对象的字节(美国客户端)? ( What I had found until now, is receiving back a JSON/ XML) (到目前为止,我发现已经收到了JSON / XML)
Thanks in advanced 提前致谢
Directly converting POJO to bytes won't work as your client (javascript or so) won't know how to convert the bytes back to POJO. 直接将POJO转换为字节将不起作用,因为您的客户端(javascript左右)将不知道如何将字节转换回POJO。 What you can do is this. 您能做的就是这个。 Say your response is objA. 假设您的回应是objA。 The do this. 做到这一点。 Convert objA to String (JSON maybe) and then Base64 encode it to get byte[]. 将objA转换为String(可能是JSON),然后Base64对其进行编码以获取byte []。 Put it inside a wrapper object objB. 将其放在包装对象objB中。 Return objB as a JSON from your service. 从您的服务返回objB作为JSON。 Your client can just take that byte[] and since it knows that the byte[] is base64 it will be able to get the original information from there. 您的客户端可以只获取该byte [],因为它知道byte []为base64,因此可以从那里获取原始信息。 May I ask the intent of doing this instead of XML/JSON? 我可以问一下代替XML / JSON的意图吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.