本文整理匯總了Java中com.alibaba.fastjson.JSONObject.toJavaObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.toJavaObject方法的具體用法?Java JSONObject.toJavaObject怎麽用?Java JSONObject.toJavaObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toJavaObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: remove
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public ResourceItem remove(String queueID, String key) {
if (!lockQueue(queueID)) {
return null;
}
Jedis jedis = jedisPool.getResource();
try {
String dataJson = jedis.hget(makeDataKey(queueID), key);
if (isNil(dataJson)) {
return null;
} else {
jedis.hdel(makeDataKey(queueID), key);
//lrem很消耗資源,盡量減少該命令操作
jedis.lrem(makePoolQueueKey(queueID), 1, key);
}
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例2: test_for_issue
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
String json = "{\"c\":\"c\"}";
TestBean tb1 = JSON.parseObject(json, TestBean.class);
assertEquals('c', tb1.getC());
TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
assertEquals('c', tb2.getC().charValue());
String json2 = JSON.toJSONString(tb2);
JSONObject jo = JSON.parseObject(json2);
TestBean tb12 = jo.toJavaObject(TestBean.class);
assertEquals('c', tb12.getC());
TestBean2 tb22 = jo.toJavaObject(TestBean2.class);
assertEquals('c', tb22.getC().charValue());
}
示例3: getFrequencyMap
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public Map<String, Frequency> getFrequencyMap() {
if (null == frequencyMap) {
synchronized (this) {
if (null == frequencyMap) {
if (StringUtils.isEmpty(frequencyInfo)) {
frequencyMap = Collections.emptyMap();
} else {
frequencyMap = new HashMap<>(1 << 4);
JSONArray array = JSONObject.parseArray(frequencyInfo);
for (Object object : array) {
JSONObject o = (JSONObject) object;
Frequency frequency = JSONObject.toJavaObject(o, Frequency.class);
StringBuilder sBuilder = new StringBuilder()
.append(frequency.getPath()).append(KEY_SEPERATOR)
.append(frequency.getVersion());
frequencyMap.put(sBuilder.toString(), frequency);
}
}
}
}
}
return frequencyMap;
}
示例4: getMessageBlock
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 解析MessageBlock
* @param packet
* @return
* @throws Exception
*/
public MessageBlock getMessageBlock(DatagramPacket packet) throws UnsupportedEncodingException{
String blockJson = new String(packet.getData(), 0, packet.getLength(), code);
JSONObject messageBlockJsonO = new JSONObject();
try {
messageBlockJsonO = JSONObject.parseObject(blockJson);
} catch (JSONException e) {
//可能是重複或者錯誤的包
return null;
}
MessageBlock msgBlock = JSONObject.toJavaObject(messageBlockJsonO, MessageBlock.class);
msgBlock.setSender(packet.getAddress().toString());
return msgBlock;
}
示例5: loadRunningScheduleServers
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static List<ScheduleServer> loadRunningScheduleServers(ZkClient zkClient,String workerType) throws Exception {
String zkPath = "/"+Constants.SAF_WORKER_ROOT+"/"+ workerType +"/"+Constants.SAF_WORKER_SERVER;
List<String> serverIDs = loadScheduleServerIds(zkClient, workerType);
if ( serverIDs != null ){
List<ScheduleServer> scheduleServers = new ArrayList<ScheduleServer>();
for( String serverID : serverIDs ){
byte[] value = zkClient.readData(zkPath+"/"+serverID,true);
if ( value != null ){
ScheduleServer server = JSONObject.toJavaObject(JSONObject.parseObject(new String(value)),ScheduleServer.class);
if ( server.isStart() ){
scheduleServers.add(server);
}
}
}
return scheduleServers;
}
return null;
}
示例6: poll
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public ResourceItem poll(String queueID) {
if (!lockQueue(queueID)) {
return null;
}
Jedis jedis = jedisPool.getResource();
try {
String firstResourceKey = jedis.lpop(makePoolQueueKey(queueID));
if (isNil(firstResourceKey)) {
return null;
}
String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
if (isNil(dataJson)) {
throw new IllegalStateException("this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
}
jedis.hdel(makeDataKey(queueID), firstResourceKey);
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例7: parse
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static BaofooCheckResp parse(String retStr) {
if (retStr != null) {
JSONObject json = new JSONObject();
String[] arr = retStr.split("&");
for (String string : arr) {
String[] keyValue = string.split("=", 2);
String key = keyValue[0];
String value = null;
if (keyValue.length < 2) {
value = "";
} else {
value = keyValue[1];
}
json.put(key, value);
}
return json.toJavaObject(BaofooCheckResp.class);
}
return new BaofooCheckResp();
}
示例8: loadScheduleServers
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 獲取指定workerType下的ScheduleServer對象
*
* @param zkClient
* @param workerType
* @return
* @throws Exception
*/
public static List<ScheduleServer> loadScheduleServers(ZkClient zkClient,String workerType) throws Exception {
String zkPath = "/"+Constants.SAF_WORKER_ROOT+"/"+ workerType +"/"+Constants.SAF_WORKER_SERVER;
List<String> serverIDs = loadScheduleServerIds(zkClient, workerType);
if ( serverIDs != null ){
List<ScheduleServer> scheduleServers = new ArrayList<ScheduleServer>();
for( String serverID : serverIDs ){
byte[] value = zkClient.readData(zkPath+"/"+serverID,true);
if ( value != null ){
ScheduleServer server = JSONObject.toJavaObject(JSONObject.parseObject(new String(value)),ScheduleServer.class);
scheduleServers.add(server);
}
}
return scheduleServers;
}
return null;
}
示例9: test_local_str
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_local_str() throws Exception {
Model model = new Model();
model.locale = Locale.CHINA;
String json = JSON.toJSONString(model);
JSONObject jsonObject = JSON.parseObject(json);
jsonObject.toJavaObject(Model.class);
}
示例10: test_local_obj
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_local_obj() throws Exception {
String json = "{\"locale\":{\"displayCountry\":\"China\",\"displayVariant\":\"\",\"displayLanguage\":\"Chinese\",\"language\":\"zh\",\"displayName\":\"Chinese (China)\",\"variant\":\"\",\"ISO3Language\":\"zho\",\"ISO3Country\":\"CHN\",\"country\":\"CN\"}}";
JSONObject jsonObject = JSON.parseObject(json);
Model model2 = jsonObject.toJavaObject(Model.class);
assertEquals("CN", model2.locale.getCountry());
assertEquals("zh", model2.locale.getLanguage());
assertEquals(Locale.CHINA.getDisplayCountry(), model2.locale.getDisplayCountry());
}
示例11: getTiandeMulticastMessage
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 拚裝還原消息
* @param msgBlockList
* @return
*/
public TiandeMulticastMessage getTiandeMulticastMessage(List<MessageBlock> msgBlockList){
/* 檢查 msgBlockList 是否正確 */
if(!veryBlockList(msgBlockList)){
throw new TiandeMultiCastException("Message block List is failed!");
}
/* 還原消息體 TiandeMulticastMessage */
Map<Integer, String> bodyMap = new HashMap<Integer, String>();
for(int i = 0; i < msgBlockList.size(); i++){
MessageBlock block = msgBlockList.get(i);
bodyMap.put(block.getIndex(), block.getBody());//保存每塊的body
}
//拚接body
StringBuilder msgSB = new StringBuilder();
for(int index = 0; index < msgBlockList.size(); index++){
String body = bodyMap.get(index);
msgSB.append(body);
}
//base64解碼
String msgBase64 = msgSB.toString();
TiandeMulticastMessage tiandeMulticastMessage = JSONObject.toJavaObject(JSONObject.parseObject(Base64.decode(msgBase64)), TiandeMulticastMessage.class);
return tiandeMulticastMessage;
}
示例12: test_2
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_2() throws Exception {
JSONObject obj = new JSONObject();
obj.put("val", "2017-08-04 15:16:41.00");
Model model = obj.toJavaObject(Model.class);
assertNotNull(model.val);
}
示例13: test_3
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_3() throws Exception {
JSONObject obj = new JSONObject();
obj.put("val", "2017-08-04 15:16:41.000");
Model model = obj.toJavaObject(Model.class);
assertNotNull(model.val);
}
示例14: dealResult
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public Object dealResult(ServiceResponse serviceResponse){
if (!"0".equals(serviceResponse.getErrorCode())) {
return null;
}
return JSONObject.toJavaObject(serviceResponse.getResult(), TransactionHistory.class);
}
示例15: getSessionUser
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public SessionUser getSessionUser() {
if (this.getData() == null || this.getData().get("user") == null) {
return null;
}
JSONObject jsonObject = (JSONObject) this.getData().get("user");
return JSONObject.toJavaObject(jsonObject, SessionUser.class);
}