Gson系列1 --- Gson 序列化与反序列化 -- 简单嵌套对象序列化

Gson系列1 --- Gson 序列化与反序列化 -- 接口类型序列化 1、简述> 接口类型序列化 接口形式的嵌套类 可以进行 序列化 ,但是 反序列化 会出错, 由于接口不可被实例化,故在反序列化时 会出错。 对于多态的形式 -- 会在后面的 TypeAdapterFactory / TypeAdapter中去解决 可参考 关于多态的绑定 RuntimeTypeAdapterFactory2、基本类public interface G... 阅读详情

1、简介

> 嵌套对象序列化
  
  与简单对象序列化基本一致,会把 嵌套对象作为一个json 的 子 json对象
    如下格式  inner 为 嵌套对象的属性名 
    {
        "nick": "A",
        "mobile": "B",
        "inner": {
           "id": 101,
           "name": "tom"
        }
    }
    

2、基本类

package sun.rain.amazing.gson.quickstart;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @a
掌握JsonObject:使用Gson库处理JSON数据 本文还有配套的精品资源,点击获取 简介:JSON是一种轻量级的数据交换格式,广泛用于Java中的数据交换。 JsonObject 是Google开发的Gson库中用于Java对象与JSON字符串相互转换的类。本文介绍 JsonObject 的基本结构和使用,展示如何在Java项目中添加Gson库依赖,以及如何通过Gson库实现数据的序列化和反序列... 阅读详情

相关推荐

实现List<Map<String, List<String>>>类型数据的SharedPreference序列化与反序列化

SharedPreferences是Android平台上用于存储少量数据的一种轻量级存储解决方案。它允许应用程序保存和检索持久的键值对,适用于保存简单的配置信息,如用户的设置选项或者一些状态标志。SharedPreferences使用起来非常方便,它默认将数据存储在一个XML文件中,数据以键值对的形式存在。序列化(Serialization)是将对象状态转换为可保持或传输的格式的过程。在序列化过程中,对象被转换成了一系列的字节,这些字节可以存储到文件中,或者通过网络发送到远程系统。

weixin_36444661的博客 1068

Gson库在Java中处理JSON数据的完全指南

Gson(Google JSON)是Google提供的一个小型Java库,主要用于将Java对象序列化成JSON格式的字符串,以及将JSON字符串反序列化为Java对象。它最早出现在2008年,并迅速成为Java社区中处理JSON数据的事实标准之一。Gson的轻量级设计和易于使用的API使其在处理JSON数据时成为开发者的首选工具。Gson默认的配置已足够满足大多数序列化和反序列化的场景需求。然而,在某些情况下,我们可能需要对Gson的行为进行微调,以解决特定的问题或优化性能。

weixin_42601134的博客 980

对象序列化实例(嵌套对象,派生类)

对象序列化实例(嵌套对象,派生类) 使用属性控制 XML 序列化 控制数组序列化 序列化数据集

手把手教你用Github提交CVE漏洞(附完整截图流程)

本文提供了在GitHub平台提交CVE漏洞的完整实战指南。从前期准备、目标搜寻与漏洞验证,到撰写规范的GitHub Issue进行披露,最后通过官方渠道完成CVE提交,手把手教你如何将安全研究成果转化为获得国际认可的CVE编号。

weixin_28309571的博客 339

C语言实现TCP聊天室:Socket编程与并发模型实战解析

网络编程是构建分布式系统的核心技术,其核心在于理解进程间通信的底层机制。TCP/IP协议栈提供了可靠的字节流传输服务,通过Socket API这一抽象接口,开发者可以在应用层建立连接、收发数据。为了高效处理多个并发连接,服务器需要采用多线程或I/O复用模型,前者为每个连接创建独立线程,逻辑清晰但资源消耗大;后者通过select、poll或epoll等系统调用监控多个文件描述符,显著提升并发能力。这些技术是构建高性能网络服务(如即时通讯、在线游戏服务器)的基础。本文以C语言实现一个简洁的TCP聊天室为例,详细

weixin_32642109的博客 293

UE4初学笔记_02_编辑器界面

不同版本可能不一样,这里是4.25 UE4编辑器主界面(也称为关卡编辑器)主要用于构建世界场景和关卡以及放置资源。 1.菜单栏 2.关卡编辑器(Level Editor)工具栏 3.“模式”(Modes)面板 4.“内容浏览器”(Content Browser)面板 5.“视口”(Viewport)面板 6.“世界大纲视图”(World Outliner)面板 7.“细节”(Details)面板 1.菜单栏 菜单栏包含“文件”(File) 、“编辑”(Edit) 、“窗口”(Win.

来自火星的猫 3097

Win11大版本更新失败:系统保留分区空间不足的终极解决方案

本文针对Windows 11大版本更新时遇到的“系统保留分区空间不足”错误,提供了详细的诊断与解决方案。核心问题在于EFI系统分区(ESP)空间过小,导致更新失败。文章重点介绍了使用傲梅分区助手等第三方工具安全扩展EFI分区的完整步骤,并提供了手动清理、使用安装介质修复等替代方案,帮助用户彻底解决更新障碍,顺利完成Win11升级。

weixin_29280219的博客 998

AI驱动的客户终身价值分析:深入理解公司的收入质量

客户终身价值(Customer Lifetime Value, CLV)是衡量客户在整个生命周期内能为企业带来多少利润的重要指标。传统的CLV计算方法往往过于简化,无法准确反映复杂的客户行为和收入模式。本文旨在介绍如何利用人工智能技术,特别是机器学习方法,构建更精确的CLV预测模型,从而帮助企业深入理解其收入质量。CLV的基本概念和商业意义传统CLV计算方法的局限性基于机器学习的CLV预测方法特征工程和模型选择策略实际应用案例和Python实现首先介绍CLV的基本概念和商业背景。

AI云原生与云计算技术学院 480

pyradiomics使用——1. 医学影像的组学特征值(Radiomics Features)提取

文章目录1. 使用插件1.1 插件安装1.2 插件使用2. 使用python代码2.1 安装2.2 使用2.2.1 官方示例2.2.2 快速使用2.2.3 其它使用3. 组学特征字段意义说明 Github地址:https://github.com/AIM-Harvard/pyradiomics 官方文档地址:https://pyradiomics.readthedocs.io/en/latest/features.html 1. 使用插件 从pyradiomics的Github仓库中可以知道,pyradio

啷个哩个啷 7382

DNA图谱分析:自动分析DNA图谱中的变异YOLOv5、YOLOv8、YOLOv10

YOLO(You Only Look Once)是一种基于卷积神经网络(CNN)的目标检测模型,因其高效的检测速度和优异的精度而广泛应用于计算机视觉任务。一次性检测:与传统的目标检测方法不同,YOLO通过回归方法同时预测多个边界框和类别信息,从而实现高效的目标检测。高精度与高速度:YOLO在检测精度和速度之间找到了平衡,适用于实时目标检测任务。

YOLO 735

AUTOSAR从入门到精通-汽车虚拟控制器(vECU)(二)

虚拟控制器的概念其实一直都存在,可能稍微有点差异,与此相关的有主机厂或供应商的ECU系统仿真或或控制策略开发工作。简而言之,虚拟控制器是一种软件工具,用于模拟ECU的功能和性能,无需实际的ECU硬件载体。source: 什么是虚拟ECU?- dSPACE空间虚拟控制器的原理主要是基于软件仿真技术,它可以模拟各种传感器的输入,执行器的输出和控制器的算法逻辑,它也可以模拟与实际控制器之间的通信接口,以便与其他ECU进行交互,如CAN总线通信等。

getusushu的博客 913

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Gson系列1 --- Gson 序列化与反序列化 -- 简单对象序列化
下一篇: Gson系列1 --- Gson 序列化与反序列化 -- 类的继承 序列化
DN-CS   BISHA
博客等级 码龄10年 75粉丝 130原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值