dungnn / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

File object after deserialization has corrupted absolute path #414

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1) Create File object with absolute path: File file = new 
File("/tmp/test.txt"). Output of file.getAbsolutePath() will be "/tmp/test.txt"
2) Create gson string from File oject created in step #1.
3) Create File object from gson string created in step #2. Output of 
file.getAbsolutePath() will be "/current_path/tmp/test.txt"

What is the expected output? What do you see instead?
Expected output in step #3 is same as on step #1 ("/tmp/test.txt"), but path of 
current dir is added in front of original path.

What version of the product are you using? On what operating system?
Using GSON 2.1, and CentOS. Same issue is on Windows 7 when writing absolute 
paths without disk name, i.e. /tmp/test.txt.

Please provide any additional information below.
Everything works well on Windows 7 when writing absolute path with disk name, 
i.e. C:/tmp/test.txt.
Attached is test file to reproduce that issue.

Original issue reported on code.google.com by rimvydas...@gmail.com on 24 Feb 2012 at 7:01

Attachments:

GoogleCodeExporter commented 9 years ago
You should just create a type adapter for File.

Original comment by limpbizkit on 25 Feb 2012 at 4:34

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 2 Sep 2012 at 9:46

GoogleCodeExporter commented 9 years ago
Jesse, Jesse, Jesse. Seriously?

Original comment by ray.ryan on 10 May 2013 at 10:23

GoogleCodeExporter commented 9 years ago
This same issue sprang up today and caused a ton of confusion. Works perfectly 
on all OSX versions of Java I've tried, but was causing issues on coworkers' 
Windows7/JDK6 machines. I'm going to add a type adapter to all my projects, but 
it seems like this would be a good candidate for 
com.google.gson.internal.bind.TypeAdapters

Original comment by prog...@gmail.com on 15 Aug 2013 at 6:33

GoogleCodeExporter commented 9 years ago
Not fixing this is a little lame...
At least attach a TypeAdapter example on this issue for the next person who 
faces it.

Original comment by kr...@cwa.to on 7 Mar 2014 at 12:06