Convert a serialized Java object to C# object [duplicate] - java

This question already has answers here:
Deserializing a java serialized file in C#
(3 answers)
Closed 6 years ago.
I have a very old Java application that I am rewriting in .net, I can't change the Java code or the old files in any way.
They have created and stored 10,000+ files that match the format described in this article, a bunch of serialized Java objects.
Question
How can I parse these Java objects in c#?
Is this even possible?
In the end, if I can read in and serialize the data, I can store it in a more universal format. When I try to deserialize the file I reach an exception, usually telling me the binary format is not valid.

A similar question has been asked here.
You have a few options. One is to write a C# class capable of reading objects in Java's serialized format (the one you linked) but this is likely very time consuming. Using C#'s native deserialization algorithm won't work because the format is different (as you've encountered).
An easier alternative is to read the objects from the files using a Java program, and save them as a more universal format such as JSON. (As recommended in an answer to another question here)

Related

parsing a json file without knowing it structure using only java [duplicate]

This question already has answers here:
How to parse JSON in Java
(36 answers)
Closed 9 months ago.
so I have, I doing a program that receives a string json with an unknown structure (since it's a variable each time I receive a new one) and it needs to parse the string to extract each key and its type (from its value).
I need to do this using only java (no spring) because I've seen solution using Jackson tree, but with the software I'm using it impossible
If someone could help I would appreciate it.
You can use JSONObject from org.json library .

How do I parse a Java file to retrieve its function names? [duplicate]

This question already has answers here:
Java : parse java source code, extract methods
(2 answers)
Closed 7 years ago.
I am working on a small program to compare two Java files. My goal is to compare the two files so that I can see what functions were added and deleted from one file to another (like a simple version control program). I am running into issues on how I should be handling these files. My current approach is to use a Scanner and use:
while(scanner.hasNext()) {
String function = scanner.next("((public|private|protected|static|final|native|synchronized|abstract|threadsafe|transient)+\\s)+[\\$_\\w\\<\\>\\[\\]]*\\s+[\\$_\\w]+\\([^\\)]*\\)?\\s*\\{?[^\\}]*\\}?");
System.out.println(function);
}
However this is not getting me any results for a file that I know has functions in it. Any tips or ideas on how to approach this?
You could use ANTLR Java grammar https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4 to get a full-blown Java parser and then use it to extract any information you need about Java files.

Is there heredoc alternative in Java (heredoc as PHP)? [duplicate]

This question already has answers here:
Does Java have support for multiline strings?
(43 answers)
Closed 7 years ago.
For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example:
BufferedWriter buffW = new BufferedWriter(fileW);
buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>");
This is mess a code, I want to write a clean such as PHP can do, but can't find on Java alternative way as example:
<?php
$mystring = <<<EOT
This is some PHP text.
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;
?>
Is there a heredoc equivalent in Java?
No, there is no direct heredoc alternative in the Java programming language.
Check this similar question.

# in java string instead of backslashes [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Raw Strings in Java?
In C# there is such a thing as # ("at sign") that can be put before string if forbidden symbols occurs. For example:
#"a\b\c"
In java I have to put backslashes
"a\\b\\c"
Is there any way in Java to make this easier?
Another way may be use equvivalent code for the symbols you want to escape.
Not really. I have made the transition not long ago and at first was constantly looking for "what is C#'s equivalent in Java for xyz?"
This is sometimes helpful but mostly frustrating. C# is a much more advanced language than Java and it will take a long time for Java to catch up.
You get used to it over time :-)

how to convert object into string or text like ascii without losing object persistence in java [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to serialize an object into a string
i want to store an object into relational database whereas that database only takes ASCII or string format.so how can i store my object to that database so that i can get back without losing persistence of that object.
I am not a java developer but I use json in such circumstances. This is a link I found on stackoverflow. Might be helpful to you. https://stackoverflow.com/questions/338586/a-better-java-json-library

Categories

Resources