<commit_before># Injection
```tut:invisible
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SparkSession
import frameless.functions.aggregate._
import frameless.TypedDataset

val conf = new SparkConf().setMaster("local[*]").setAppName("frameless repl").set("spark.ui.enabled", "false")
val spark = SparkSession.builder().config(conf).appName("REPL").getOrCreate()
implicit val sqlContext = spark.sqlContext
spark.sparkContext.setLogLevel("WARN")

import spark.implicits._
``` 
Injection lets us define encoders for types that do not have one, by injecting `A` into an encodable type `B`.
This is the definition of the injection typeclass : 
```scala
trait Injection[A, B] extends Serializable {
  def apply(a: A): B
  def invert(b: B): A
}
``` 
## Example
Let's define a simple case class : 
```tut:book
case class Person(age: Int, birthday: java.util.Date)
``` 
And an instance of a `TypedDataset` :
```tut:book:fail
val people = Seq(Person(42, new java.util.Date))
val personDS = TypedDataset.create(people)
``` 
Looks like we can't, a `TypedEncoder` instance of `Person` is not available, or more precisely for `java.util.Date`. 
But we can define a injection from `java.util.Date` to an encodable type, like `Long` : 
```tut:book
import frameless._<commit_msg>isolate failing statement<commit_after># Injection
```tut:invisible
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SparkSession
import frameless.functions.aggregate._
import frameless.TypedDataset

val conf = new SparkConf().setMaster("local[*]").setAppName("frameless repl").set("spark.ui.enabled", "false")
val spark = SparkSession.builder().config(conf).appName("REPL").getOrCreate()
implicit val sqlContext = spark.sqlContext
spark.sparkContext.setLogLevel("WARN")

import spark.implicits._
``` 
Injection lets us define encoders for types that do not have one, by injecting `A` into an encodable type `B`.
This is the definition of the injection typeclass : 
```scala
trait Injection[A, B] extends Serializable {
  def apply(a: A): B
  def invert(b: B): A
}
``` 
## Example
Let's define a simple case class : 
```tut:book
case class Person(age: Int, birthday: java.util.Date)
val people = Seq(Person(42, new java.util.Date))
``` 
And an instance of a `TypedDataset` :
```tut:book:fail
val personDS = TypedDataset.create(people)
``` 
Looks like we can't, a `TypedEncoder` instance of `Person` is not available, or more precisely for `java.util.Date`. 
But we can define a injection from `java.util.Date` to an encodable type, like `Long` : 
```tut:book
import frameless._
{'fraction_non_alphanumeric': 0.12923076923076923, 'fraction_numerical': 0.0015384615384615385, 'mean_word_length': 5.486284289276808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '752235', 'n_tokens_mistral': 868, 'n_tokens_neox': 829, 'n_words': 267}