Comments (4)
@MarconZet I think you can take this as the next priority, given that we got discouraged from delving into #7 🤔
from akka-serialization-helper.
Not sure how this can be achieved tho... compiler plugin maybe? 🤔
from akka-serialization-helper.
Pls start with runtime-reflection-based solution, similar to what's currently in ArchUnit (but without using ArchUnit as a dependency):
// The below tests (roughly) check that the classes used as messages/events/state in Akka
// are always marked as CborSerializable, to ensure that Jackson CBOR and not legacy Java serialization
// is used for their serialization.
// For Akka to ensure that condition statically, a major redesign would be necessary -
// all methods like `ask`, `tell`, `Effect.persist` etc. would need to require an implicit `Codec` (?) parameter.
// The below tests do NOT ensure that the Jackson serialization of messages/events/state will actually succeed in the runtime.
"Messages, events and entity state classes" should {
"implement CborSerializable" in {
classes
.should(new ArchCondition[JavaClass]("only use CborSerializable message/event/state types") {
override def check(clazz: JavaClass, events: ConditionEvents): Unit = {
clazz.getAllMethods.asScala.foreach { method =>
def checkType(tpe: Type, category: String, failsWhen: String): Unit = {
tpe match {
case clazz: Class[_] if clazz.getPackageName.startsWith("akka") =>
// OK, acceptable
case clazz: Class[_] if clazz == classOf[scala.Nothing] =>
// OK, acceptable
case clazz: Class[_] if !classOf[CborSerializable].isAssignableFrom(clazz) =>
val message =
s"Type ${clazz.getName} is used as Akka $category (as observed in the return type of method ${method.getFullName}), " +
s"but does NOT extend CborSerializable; this will fail in the runtime $failsWhen"
events.add(SimpleConditionEvent.violated(clazz, message))
case _ =>
}
}
val returnType = method.getRawReturnType
val genericReturnType = method.reflect.getGenericReturnType
if (returnType.isEquivalentTo(classOf[akka.persistence.typed.scaladsl.ReplyEffect[_, _]])) {
genericReturnType match {
case parameterizedType: ParameterizedType =>
val Array(eventType, stateType) = parameterizedType.getActualTypeArguments
checkType(eventType, "event", "when saving to the journal")
checkType(stateType, "persistent state", "when doing a snapshot")
case _ =>
}
} else if (returnType.isEquivalentTo(classOf[akka.projection.eventsourced.EventEnvelope[_]])) {
genericReturnType match {
case parameterizedType: ParameterizedType =>
val Array(eventType) = parameterizedType.getActualTypeArguments
checkType(eventType, "event", "when saving to the journal")
case _ =>
}
} else if (returnType.isEquivalentTo(classOf[akka.actor.typed.Behavior[_]])) {
genericReturnType match {
case parameterizedType: ParameterizedType =>
val Array(messageType) = parameterizedType.getActualTypeArguments
checkType(messageType, "message", "when sending a message outside of the current JVM")
case _ =>
}
}
}
}
})
.check(importedProductionClasses)
}
}
from akka-serialization-helper.
^ This is very suboptimal since e.g. it can't ever check the type of objects passed to tell
/ask
though :/
from akka-serialization-helper.
Related Issues (20)
- Add `verbose` logs to Codec Registration Checker Compiler Plugin
- Set sbt keys for all `ashSerializabilityCheckerCompilerPlugin` flags
- Update `AkkaCodecs` usage in `examples/`
- Add support for Scala 3 HOT 1
- Enable security reports from `Dependabot`
- Fix critical Log4J vulnerabilities HOT 1
- Support for `Laguna` - add persistence schema checks to CI
- Support for `Laguna` - tidy up the mess with multiple ASH cache directories
- Updata scala versions to `2.12.17` and `2.13.9`
- In README document jackson ScalaObjectDeserializerModule HOT 2
- Support for native serializable types and/or exclusions HOT 14
- Support for `Laguna` - fix persistence schema check in CI HOT 1
- Question, adding many options HOT 3
- `OverlappingFileLockException` from `SerializerCheckCompilerPluginComponent$$anon$1.interactWithTheCacheFile` HOT 15
- `spray.json.JsonParser$ParsingException: Unexpected end-of-input` at `PersistenceSchemaWriter`
- Untangle file access in codec-registration-checker-compiler-plugin
- Pekko support HOT 2
- Snapshots are published for each Scala minor version
- Snapshots are published as `0.0.0+...` version, regardless of the latest tag
- Restore Scala Steward (?) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from akka-serialization-helper.