简体   繁体   English

泽西岛客户端接收pojo我们的字节

[英]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.

相关问题 如何在客户端接收响应? - How to receive response on client side? 在客户端获取文件大小(以字节为单位) - Get file size (in bytes) on client side 在客户端接收重定向的 POST 请求 - POST request to receive redirect on client side Firebase,无法接收通知(客户端) - firebase,can not receive notifications(client side) 已发送泽西岛2服务器+客户端事件源无法正常工作 - Jersey 2 Server Sent + client side Event source not working properly PayPal 结帐:仅使用客户端代码接收付款是否安全? - PayPal Checkout: Is it safe to receive a payment with only client-side code? 重新连接时客户端 SignalR 收不到消息 - Client side SignalR on reconnect doesn't receive messages 从Flash接收数据并在angularJS客户端上显示 - receive data from flash and display on angularJS client side 客户端在服务器端渲染中究竟收到了什么? - What exactly does client receive in server-side rendering? 是否有一种可能的方法在客户端和服务器端之间发送和接收对象(使用 proto)并且对象被定义在客户端? - Is there a possible way to send and receive objects (with proto) between client and server side with object being defined client-side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM