Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to pass an ArrayList<Object> from server to client?
After i have to put my ArrayList in a JTable.
You have to serialize it when you write to the socket and deserialize when you read from the socket.
Ultimately you're sending Strings on the wire. Transport doesn't know or care anything about objects on either end of the conversation. TCP/IP is language independent.
You have many choices to choose from:
Java Serializable - this means sending byte code on the wire.
XML. You can use JAXB.
JSON. You can use Jackson.
Custom protocol of your own design.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making an instant messenger in Java and I want to add the ability to send images as well as text. The first thing that came to mind was to make new Sockets and input and output streams. Firstly, will this work and is it good practice. Secondly, if this doesn't work then how does the receiving end of the message figure out if what it is receiving is an image or a String?
An output stream contains bytes, which you have to build into messages. The reader knows which type of data you sent, because the sender will have to say which type of message it is sending.
e.g. if you write say "image" as a string you could assume that what follows it is an image.
Remember that you're not transmitting Strings or Images, you're exchanging Messages. A message should have a content or message type associated with it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have encountered a problem using byte array. The exception it suggested to me that I ought to use Blob in the properties of HttpServletRequest , but I can not find information about this.
The complete package: com.google.appengine.api.datastore.Blob
Can you say I like this class uses? or any web which has examples
There is an example of extracting blobs, I think here.
http://www.programcreek.com/java-api-examples/index.php?api=org.apache.commons.fileupload.FileUpload
I'm not familiar with the datastore, but as far as I know, Blob types are 'just' wrappers for byte arrays.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In JAX-RS there is an option to define a custom entity provider(message body workers or message body readers and writers) so that you can map a java bean to MIME type (say application/myBean).
Are there any scenario where one would need it?
One reason for defining custom Media Types is defining tighter contracts. For instance using the header Accept: application/vnd.com.example.customer+xml defines on protocol-level that a list of orders won't be accepted. This is not possible with using application/xml.
If you want to use custom Media Types you need custom providers for serialization.
There is a long going debate if this is a good idea or not.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I trying to send an object by server to receiver or reverse.However, most of time it is true and done completely but sometimes when I send an object, the receiver get the object that I sent before it and object are sent by sender lost.I have used Socket in my project and read and write by ObjectInputStream and ObjectOutputStream.
If you're sending the same object with different values you need to call ObjectOutputStream.reset() before the second send if you want the receiver to get the changed object. Or call writeUnshared() instead of writeObject().
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How to load JSON from socket and parse values of elements ?
Take a look at the Java tutorial on Reading from a Socket.
You can then use a JSON parser such as google-gson to convert the JSON string to a Java object.
Reading from a socket is a kind of basic java
About JSON, if you need performance I recommend you to take a look to Jackson ( http://jackson.codehaus.org/ ) as it's one of the fastest implementation available
(see at http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking )
Have a look at REST Assured. It makes it very easy to parse json data using JsonPath.