# auto-value-parcel **Repository Path**: ts_ohos/auto-value-parcel ## Basic Information - **Project Name**: auto-value-parcel - **Description**: 一个自动值的生成工具,支持简单序列化处理,使用它不仅可以节约大量的开发时间,还会让代码更加的简洁。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-03 - **Last Updated**: 2022-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # auto-value-parcel 本项目是基于源项目rharter/auto-value-parcel进行harmonyos化移植和开发的,可以通过项目标签以及[github地址](https://github.com/rharter/auto-value-parcel) ## 项目介绍 ### 项目名称:auto-value-parcel ### 所属系列:harmonyos的第三方组件适配移植 ### 功能: auto-value-parcel:一个自动值的生成工具,支持简单序列化处理,使用它不仅可以节约大量的开发时间,还会让代码更加的简洁。 ### 项目移植状态:全部移植 ### 调用差异:基本没有使用差异 ### 原项目地址:https://github.com/rharter/auto-value-parcel ### 编程语言:Java ## 安装教程 - 1.项目根目录的build.gradle中的repositories添加: ```groovy buildscript { repositories { ... mavenCentral() } ... } allprojects { repositories { ... mavenCentral() } } ``` - 2.由于此组件是基于谷歌autovalue组件基础上进行拓展移植的,所以使用时需要先进行autovalue的引入([autovalue地址](https://github.com/google/auto)) 添加Gradle依赖:可以直接下载har包或通过maven引入: 普通的序列化使用: ```groovy dependencies { //第一步先引入autovalue的包 implementation 'com.google.auto.value:auto-value:1.8.2' annotationProcessor 'com.google.auto.value:auto-value:1.8.2' //第二步再引入auto_value_parcel的包 implementation project(":auto_value_parcel") } ``` 或 ```groovy dependencies { //第一步先引入autovalue的包 implementation 'com.google.auto.value:auto-value:1.8.2' annotationProcessor 'com.google.auto.value:auto-value:1.8.2' //第二步再引入auto_value_parcel的包 implementation 'com.gitee.ts_ohos:auto_value_parcel:1.0.0' } ``` 如果需要使用自定义的TypeAdapter,则还需要引入adapter ```groovy dependencies { //第一步先引入autovalue的包 implementation 'com.google.auto.value:auto-value:1.8.2' annotationProcessor 'com.google.auto.value:auto-value:1.8.2' //第二步再引入auto_value_parcel的包 implementation project(":auto_value_parcel") implementation project(":adapter") } ``` 或 ```groovy dependencies { //第一步先引入autovalue的包 implementation 'com.google.auto.value:auto-value:1.8.2' annotationProcessor 'com.google.auto.value:auto-value:1.8.2' //第二步再引入auto_value_parcel的包 implementation project(":auto_value_parcel") implementation 'com.gitee.ts_ohos:adapter:1.0.0' } ``` ## 使用说明 编写抽象类实现@AutoValue注解,然后实现ohos序列化Parcel接口,通过build->build hap进行编译 ```java @AutoValue public abstract class Foo implements Parcel { public abstract String bar(); } ``` ## TypeAdapters TypeAdapter允许您为属性定义自定义反序列化逻辑 手动包裹和解开这些属性。 ```java public class DateTypeAdapter implements TypeAdapter { public Date fromParcel(Parcel in) { return new Date(in.readLong()); } public void toParcel(Date value, Parcel dest) { dest.writeLong(value.getTime()); } } ``` 使用自定义TypeAdapter,在AutoValue类上对特定的属性进行标识,用TypeAdapter序列化的任何属性的' ParcelAdapter '。 ```java @AutoValue public abstract class Foo implements Parcel { @ParcelAdapter(DateTypeAdapter.class) public abstract Date date(); } ``` ## 移植版本 Tag 0.2.9 ## 版本迭代 - v1.0.0 项目初次提交 ## License ``` Copyright 2015 Ryan Harter. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```