[JAVA-1057] Saving Chinese becomes unreadable string Created: 04/Dec/13  Updated: 10/Apr/14  Resolved: 30/Dec/13

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: James Lee Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OSX 10.9, MongoDB 2.4.8, java driver 2.11.3


Attachments: Text File test.txt    

 Description   

read string from a file, the string is readable,
but after saving to MongoDB, the string became something like this:发生 in fact this is still Chinese, but why it looks like this?

I tried to use mongo command line to save Chinese, everything is fine.



 Comments   
Comment by Jeffrey Yemin [ 30/Dec/13 ]

As I have not heard back from you in a while, I'm closing this issue, but please feel free to re-open if you still think there is a bug.

Comment by Jeffrey Yemin [ 05/Dec/13 ]

It works fine for me:

public class JAVA1057 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("/Users/jeff/Downloads/JAVA1057.txt"),
                                                                                             Charset.forName("UTF-8")));
        String line = reader.readLine();
        String lastLine = null;
        while (line != null) {
            lastLine = line;
            line = reader.readLine();
        }
        System.out.println(lastLine);
 
        MongoClient mc = new MongoClient();
        DBCollection coll = mc.getDB("test").getCollection("JAVA1057");
        coll.insert(new BasicDBObject("_id", 1).append("text", lastLine));
 
        DBObject document = coll.findOne();
 
        System.out.println(document.get("text"));
    }
}

Did you remember to set the character set properly when reading in the file?

Comment by James Lee [ 05/Dec/13 ]

file that contains Chinese string

Comment by James Lee [ 05/Dec/13 ]

Sorry, seems the jira website could convert that string to a readable string.
what's in my mongodb is "p" : "取消", and this is also shown on my website.

for test case, I uploaded a file, that contains the Chinese string.
please try to read that string and save to db

Comment by Jeffrey Yemin [ 05/Dec/13 ]

Can you provide a test case so that we can try to reproduce it?

Generated at Thu Feb 08 08:53:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.