java pojo xml_XML格式的转换成java Class PoJO

依耐pom文件:

913511df041e

com.alibaba

fastjson

1.1.41

com.thoughtworks.xstream

xstream

1.4.7

org.json

json

20140107

xml转json工具类:

import org.json.JSONObject;

import org.json.XML;

/**

*

* Create Date: 2014年9月28日 下午8:04:12

* Author XieXianbin

* Source Repositories Address:

*/

public classXml2Json {

// JSON格式缩进空格数

public static intPRETTY_PRINT_INDENT_FACTOR=4;

/**

*

*@paramxml

*@return

*/

public staticJSONObject conert2JSONObject(String xml){

JSONObject xmlJSONObj = XML.toJSONObject(xml);

return xmlJSONObj;

}

/**

*

*@paramxml

*@return

*/

public staticString conert2String(String xml){

JSONObject xmlJSONObj = XML.toJSONObject(xml);

String jsonString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);

return jsonString;

}

}

1.xml转成json

913511df041e

2. json 转成 java Class PoJo

913511df041e

913511df041e

913511df041e

3.对java文件处理工具类:

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class ClassBuilder {

public static void main(String[] args) {

//1.读取文件

String filePath="E:\\gitWorkSpace\\SJDKSer\\src\\main\\java\\com\\yanxintec\\sjdk\\pojo\\instinctnew\\";

//可改变的类名

String changeClassName="A_Accountant_Solicitor.java";

//文件读取路径

filePath=filePath+changeClassName;

BufferedReader br = null;

try{

br = new BufferedReader(new FileReader(filePath));

String data="";

while((data = br.readLine())!=null){

//System.out.println(data);

if(data.contains("private String")){

String str=data.substring(data.indexOf("String")+"String".length()+1, data.indexOf(";"));

data="\t@XmlElement(name = \""+str+"\")\n"+data;

String temp="";

temp=data.substring(data.indexOf("String")+"String".length()+1, data.indexOf(";"));

String substring = temp.substring(1);

String firstChar=temp.substring(0,1).toLowerCase();

substring=firstChar+substring;

/*System.out.println(str);

System.out.println(data);

System.out.println(substring);*/

System.out.println(data.replace(" "+str, " "+substring));

}

}

}catch(Exception e){

e.printStackTrace();

}

finally{

if(null!=br){

try {

br.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

}

---------------------------------------------

自己处理的方式,写在文章里,大家有更好的方式,也可以推荐给我!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值