-
-
Save czegarram/6f53138ec837b2c38a45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
registroFactory.testing =function ($scope){ | |
var cad = ""; | |
cad = $sessionStorage['JSESSION']; | |
var response={}; | |
var datos={}; | |
var empresa={ | |
'@id':1, | |
idEmpresa:3, | |
ruc:"1077884561"}; | |
var empresita={'@id':2,idEmpresa:9, | |
ruc:"1077884222"}; | |
var pais={'@id':3,idPais:3, | |
nombre:"Eslovaquia"}; | |
datos['empresa']= empresa; | |
datos['empresita'] = empresita; | |
datos['pais'] = pais; | |
response.observacion = "LOL"; | |
response.result = false; | |
response.data = datos; | |
console.log(response); | |
$http({ | |
method : 'POST', | |
url : '/api/public/test', | |
data : response | |
}) | |
.success(function(status) { | |
if(status==200){ | |
console.log('me llegoooo'); | |
} | |
}); | |
}; |
This file contains hidden or 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
package edu.pe.pm.ilcb.sga.rest.objects; | |
import java.util.Map; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
import com.fasterxml.jackson.annotation.JsonIdentityInfo; | |
import com.fasterxml.jackson.annotation.ObjectIdGenerators; | |
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id") | |
@Entity | |
@Table | |
public class RestDataResponse { | |
private String observacion; | |
private Boolean result; | |
private Map<String,Object> data; | |
public RestDataResponse(){ | |
} | |
public RestDataResponse(String observacion, boolean result ) { | |
this.observacion = observacion; | |
this.result = result; | |
} | |
@Column | |
public String getObservacion() { | |
return observacion; | |
} | |
public void setObservacion(String observacion) { | |
this.observacion = observacion; | |
} | |
@Column | |
public Boolean getResult() { | |
return result; | |
} | |
public void setResult(Boolean result) { | |
this.result = result; | |
} | |
@Column | |
public Map<String, Object> getData() { | |
return data; | |
} | |
public void setData(Map<String, Object> data) { | |
this.data = data; | |
} | |
} |
This file contains hidden or 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
import java.util.HashMap; | |
import java.util.Map; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
@Entity | |
@Table | |
public class Message implements java.io.Serializable { | |
/** | |
* | |
*/ | |
private static final long serialVersionUID = 1L; | |
private Boolean result=false; | |
private String message=""; | |
private Map<String,Object> data = new HashMap<String,Object> (); | |
public Message(){ | |
} | |
public Message(boolean result, String message) { | |
this.result = result; | |
this.message = message; | |
} | |
@Column | |
public Boolean getResult() { | |
return result; | |
} | |
public void setResult(Boolean result) { | |
this.result = result; | |
} | |
@Column | |
public String getMessage() { | |
return message; | |
} | |
public void setMessage(String message) { | |
this.message = message; | |
} | |
@Column | |
public Map<String, Object> getData() { | |
return data; | |
} | |
public void setData(Map<String, Object> data) { | |
this.data = data; | |
} | |
@Override | |
public String toString() { | |
return "Message [result=" + result + ", message=" + message + ", data=" | |
+ data + "]"; | |
} | |
} |
This file contains hidden or 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
@RequestMapping( headers = "Content-Type=application/json",value="/test", method=RequestMethod.POST) | |
@ResponseStatus(value = HttpStatus.OK) | |
public @ResponseBody RestMessageResponse testCesar(@RequestBody RestDataResponse data){ | |
System.out.println(data.getData()); | |
return new RestMessageResponse("Enter"); | |
} |
This file contains hidden or 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
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.hibernate.SessionFactory; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import org.springframework.test.context.transaction.TransactionConfiguration; | |
import org.springframework.transaction.annotation.Transactional; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import edu.pe.pm.ilcb.sga.domain.AiAlumno; | |
import edu.pe.pm.ilcb.sga.domain.AiEmpresa; | |
import edu.pe.pm.ilcb.sga.helpers.mvc.HibernateAwareObjectMapper; | |
@TransactionConfiguration | |
@Transactional | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(locations={"classpath:testContext.xml"}) | |
public class test2 { | |
@Autowired | |
SessionFactory sf; | |
@Test | |
public void testingHibernateToJson(){ | |
HibernateAwareObjectMapper mapper = new HibernateAwareObjectMapper(); | |
@SuppressWarnings("unchecked") | |
List<AiEmpresa> avisos = | |
sf.getCurrentSession().createQuery("select e from AiEmpresa e " | |
+ "inner join fetch e.aiEmpresaSeguridad es " | |
+ "inner join fetch e.pais p ").list(); | |
try { | |
Message m = new Message (true,"Hola Mundo"); | |
//m.getData().put("Aviso",avisos.get(0)); | |
//avisos.get(0).setAiEmpresaSeguridad(null); | |
String json = mapper.writeValueAsString(m); | |
System.out.println( json); | |
AiAlumno a = new AiAlumno(); | |
a.setNombre("Perio Alberto"); | |
List<Object> empresas = new ArrayList<Object>(); | |
empresas.add(avisos.get(0)); | |
//empresas.add(a); | |
String jsonEmpresa = mapper.writeValueAsString(empresas); | |
try { | |
AiEmpresa[] myObjects = mapper.readValue(jsonEmpresa, AiEmpresa[].class); | |
System.out.println(myObjects[0]); | |
Message message = mapper.readValue(json, Message.class); | |
//System.out.println( ( (AiEmpresa) message.getData().get("Aviso") ).getAiEmpresaSeguridad()); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} catch (JsonProcessingException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment