Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 74886ab
Showing
12 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.classpath | ||
.project | ||
.settings/ | ||
target/ | ||
tmp | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# algaworks-jsf-facesmessage-pagredirecionamento | ||
|
||
Código referente ao artigo escrito para AlgaWorks | ||
|
||
Saiba mais em: | ||
|
||
http://blog.algaworks.com | ||
|
||
### Rodando o projeto | ||
|
||
Use: | ||
|
||
``` shell | ||
$ mvn jetty:run | ||
``` | ||
|
||
Acesse: | ||
|
||
[http://localhost:8080/rachinha/jogadores](http://localhost:8080/rachinha/jogadores) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mvn archetype:generate -DgroupId=com.algaworks.exemplos -DartifactId=algaworks-java-serialVersionUID -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<project | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" | ||
> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.algaworks.exemplos</groupId> | ||
<artifactId>algaworks-java-serialVersionUID</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<name>algaworks-java-serialVersionUID</name> | ||
|
||
<url>http://algaworks.com</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/algaworks/exemplos/serialversionuid/ex1/Clube.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex1; | ||
|
||
public class Clube implements java.io.Serializable { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/algaworks/exemplos/serialversionuid/ex2/Clube.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex2; | ||
|
||
public class Clube implements java.io.Serializable { | ||
|
||
|
||
String nome; | ||
//int titulos; | ||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/algaworks/exemplos/serialversionuid/ex3/Clube.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex3; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class Clube implements java.io.Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String nome; | ||
|
||
private int titulos; | ||
|
||
private LocalDate nascimento; | ||
|
||
public String getNome() { | ||
return nome; | ||
} | ||
|
||
public void setNome(String nome) { | ||
this.nome = nome; | ||
} | ||
|
||
public int getTitulos() { | ||
return titulos; | ||
} | ||
|
||
public void setTitulos(int titulos) { | ||
this.titulos = titulos; | ||
} | ||
|
||
public LocalDate getNascimento() { | ||
return nascimento; | ||
} | ||
|
||
public void setNascimento(LocalDate nascimento) { | ||
this.nascimento = nascimento; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/algaworks/exemplos/serialversionuid/ex3/Desserializador.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex3; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.ObjectInputStream; | ||
|
||
public class Desserializador { | ||
|
||
public static void main(String... args) throws Exception { | ||
FileInputStream fis = new FileInputStream("/tmp/saopaulo.ser"); | ||
ObjectInputStream ois = new ObjectInputStream(fis); | ||
Clube clube = (Clube) ois.readObject(); | ||
ois.close(); | ||
|
||
System.out.println("Pronto! Objeto descerializado."); | ||
System.out.println("Nome: " + clube.getNome()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/algaworks/exemplos/serialversionuid/ex3/Serializador.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex3; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.time.LocalDate; | ||
import java.time.Month; | ||
|
||
public class Serializador { | ||
|
||
public static void main(String... args) throws Exception { | ||
Clube oMelhorClube = new Clube(); | ||
oMelhorClube.setNome("São Paulo Futebol Clube"); | ||
oMelhorClube.setTitulos(2147483647);// por 1 não tenho que declarar long | ||
oMelhorClube.setNascimento(LocalDate.of(1930, Month.JANUARY, 27)); | ||
|
||
FileOutputStream fos = new FileOutputStream("/tmp/saopaulo.ser"); | ||
ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
oos.writeObject(oMelhorClube); | ||
oos.close(); | ||
System.out.println("Pronto! Objeto serializado."); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/algaworks/exemplos/serialversionuid/ex4/Clube.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex4; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.time.LocalDate; | ||
|
||
public class Clube implements java.io.Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String nome; | ||
|
||
private int titulos; | ||
|
||
private LocalDate nascimento; | ||
|
||
private transient String hino; | ||
|
||
private void writeObject(ObjectOutputStream out) throws IOException { | ||
out.defaultWriteObject(); | ||
|
||
out.writeObject(hino); | ||
|
||
System.out.println("Serializacao customizada."); | ||
} | ||
|
||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { | ||
in.defaultReadObject(); | ||
|
||
hino = (String) in.readObject(); | ||
|
||
System.out.println("Desserializacao customizada."); | ||
} | ||
|
||
public String getNome() { | ||
return nome; | ||
} | ||
|
||
public void setNome(String nome) { | ||
this.nome = nome; | ||
} | ||
|
||
public int getTitulos() { | ||
return titulos; | ||
} | ||
|
||
public void setTitulos(int titulos) { | ||
this.titulos = titulos; | ||
} | ||
|
||
public LocalDate getNascimento() { | ||
return nascimento; | ||
} | ||
|
||
public void setNascimento(LocalDate nascimento) { | ||
this.nascimento = nascimento; | ||
} | ||
|
||
public String getHino() { | ||
return hino; | ||
} | ||
|
||
public void setHino(String hino) { | ||
this.hino = hino; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/algaworks/exemplos/serialversionuid/ex4/Desserializador.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex4; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.ObjectInputStream; | ||
|
||
public class Desserializador { | ||
|
||
public static void main(String... args) throws Exception { | ||
FileInputStream fis = new FileInputStream("/tmp/saopaulo.ser"); | ||
ObjectInputStream ois = new ObjectInputStream(fis); | ||
Clube clube = (Clube) ois.readObject(); | ||
ois.close(); | ||
|
||
System.out.println("Pronto! Objeto descerializado."); | ||
System.out.println("Nome: " + clube.getNome() + ", Hino: " + clube.getHino()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/algaworks/exemplos/serialversionuid/ex4/Serializador.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.algaworks.exemplos.serialversionuid.ex4; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.time.LocalDate; | ||
import java.time.Month; | ||
|
||
public class Serializador { | ||
|
||
public static void main(String... args) throws Exception { | ||
Clube oMelhorClube = new Clube(); | ||
oMelhorClube.setNome("São Paulo Futebol Clube"); | ||
oMelhorClube.setTitulos(2147483647);// por 1 não tenho que declarar long | ||
oMelhorClube.setNascimento(LocalDate.of(1930, Month.JANUARY, 27)); | ||
oMelhorClube.setHino("Salve o tricolor paulista... Amado clube brasileiro."); | ||
|
||
FileOutputStream fos = new FileOutputStream("/tmp/saopaulo.ser"); | ||
ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
oos.writeObject(oMelhorClube); | ||
oos.close(); | ||
System.out.println("Pronto! Objeto serializado."); | ||
} | ||
} |