Skip to content

Commit

Permalink
[WIP] remove json4s from linkis (apache#4368)
Browse files Browse the repository at this point in the history
* remove json4s from linkis

* use jsonpath to read json value

* fix unknown dependency

* improve jsonpath usage

* optimize code

* trigger rebuild

* trigger rebuild

* optimize code

* optimize code

* fix circular reference object

* remove unused jackson

---------

Co-authored-by: gf13871 <[email protected]>
  • Loading branch information
GuoPhilipse and tclxgf13871 authored Apr 13, 2023
1 parent 78b7f79 commit 3702d91
Show file tree
Hide file tree
Showing 36 changed files with 371 additions and 825 deletions.
25 changes: 0 additions & 25 deletions linkis-commons/linkis-httpclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@
<artifactId>httpmime</artifactId>
<version>${httpmime.version}</version>
</dependency>

<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
<version>${json4s.version}</version>
<exclusions>
<exclusion>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
16 changes: 0 additions & 16 deletions linkis-commons/linkis-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,6 @@
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
<version>${json4s.version}</version>
<exclusions>
<exclusion>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.linkis.rpc.transform

import org.apache.linkis.DataWorkCloudApplication
import org.apache.linkis.common.utils.Logging
import org.apache.linkis.protocol.message.RequestProtocol
import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary
Expand All @@ -28,13 +27,6 @@ import org.apache.linkis.server.{EXCEPTION_MSG, Message}

import org.apache.commons.lang3.ClassUtils

import java.lang.reflect.{ParameterizedType, Type}
import java.util

import scala.collection.JavaConverters.mapAsScalaMapConverter

import org.json4s.{DefaultFormats, Formats, Serializer}

private[linkis] trait RPCProduct {

def toMessage(t: Any): Message
Expand All @@ -52,21 +44,10 @@ private[linkis] object RPCProduct extends Logging {
private[rpc] val CLASS_VALUE = "rpc_object_class"
private[rpc] val OBJECT_VALUE = "rpc_object_value"

private[rpc] implicit var formats: Formats =
DefaultFormats + JavaCollectionSerializer + JavaMapSerializer

private var serializerClasses: List[Class[_]] = List.empty

private val rpcProduct: RPCProduct = new RPCProduct {

private val rpcFormats =
DataWorkCloudApplication.getApplicationContext.getBeansOfType(classOf[RPCFormats])

if (rpcFormats != null && !rpcFormats.isEmpty) {
val serializers = rpcFormats.asScala.map(_._2.getSerializers).toArray.flatMap(_.iterator)
setFormats(serializers)
}

override def toMessage(t: Any): Message = {
if (t == null) {
throw new DWCURIException(
Expand Down Expand Up @@ -105,29 +86,6 @@ private[linkis] object RPCProduct extends Logging {

}

private[rpc] def setFormats(serializer: Array[Serializer[_]]): Unit = {
this.formats = (serializer :+ JavaCollectionSerializer :+ JavaMapSerializer).foldLeft(
DefaultFormats.asInstanceOf[Formats]
)(_ + _)
serializerClasses = formats.customSerializers
.map(s => getActualTypeClass(s.getClass.getGenericSuperclass))
.filter(_ != null) ++: List(classOf[util.List[_]], classOf[util.Map[_, _]])
logger.info(
"RPC Serializers: " + this.formats.customSerializers
.map(_.getClass.getSimpleName) + ", serializerClasses: " +
"" + serializerClasses
)
}

private def getActualTypeClass(classType: Type): Class[_] = classType match {
case p: ParameterizedType =>
val params = p.getActualTypeArguments
if (params == null || params.isEmpty) null
else getActualTypeClass(params(0))
case c: Class[_] => c
case _ => null
}

private[rpc] def isRequestProtocol(obj: Any): Boolean = obj.isInstanceOf[RequestProtocol]

private[rpc] def isScalaClass(obj: Any): Boolean =
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions linkis-commons/linkis-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>

<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
<version>${json4s.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package org.apache.linkis.storage.domain
import java.lang.reflect.Type

import com.google.gson.GsonBuilder
import org.json4s.DefaultFormats
import org.json4s.jackson.Serialization.write

/**
* @param id
Expand Down Expand Up @@ -58,23 +56,21 @@ case class MethodEntity(

object MethodEntitySerializer {

implicit val formats = DefaultFormats
import org.json4s.jackson.JsonMethods._
val gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create

/**
* Serialized to code as a MethodEntity object 序列化为code为MethodEntity对象
* @param code
* @return
*/
def deserializer(code: String): MethodEntity = parse(code).extract[MethodEntity]
def deserializer(code: String): MethodEntity = gson.fromJson(code, classOf[MethodEntity])

/**
* Serialize MethodEntity to code 序列化MethodEntity为code
* @param methodEntity
* @return
*/
def serializer(methodEntity: MethodEntity): String = write(methodEntity)
def serializer(methodEntity: MethodEntity): String = gson.toJson(methodEntity)

/**
* Serialize a java object as a string 序列化java对象为字符串
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
<groupId>org.apache.linkis</groupId>
<artifactId>linkis-hadoop-common</artifactId>
</exclusion>
<exclusion>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Loading

0 comments on commit 3702d91

Please sign in to comment.