修复解析垃圾分类数据乱码问题

master
ZHD 5 years ago
parent 11d94ccd1a
commit 7619a31521
  1. 6
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -25,8 +25,12 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Random;
@ -86,7 +90,7 @@ class DemoApplicationTests {
@Test
void loadData() throws FileNotFoundException {
Gson gson = new Gson();
MyGarbage g = gson.fromJson(new FileReader("src/main/resources/garbage.json"), MyGarbage.class);
MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class);
for (Garbage garbage : g.getList()) {
garbageDao.save(garbage);
}

Loading…
Cancel
Save