[Ethereum] How to return struct when function is called

selfdestructsoliditystruct

I'd like to return struct type User. However, when I tried the following getUser function, it returns an error. Is there any way that struct data would be returned from a function?

Contract

struct User{
    uint256 user_id;
    bytes32 name;
    bytes32 address;
    bytes32 birth_day;
}
mapping (uint256 => User) public users;

function getUser(uint256 user_id) constant returns (User) {
        return users[user_id];
}

Error

client/lib/contracts/User.sol: Solidity errors: :125:58: Error: Expected type name

function getUser(uint256 user_id) constant returns (struct User) {

Best Answer

You can not return a struct because Solidity implements them only as a loose bag of variables, they are not real objects.

You can use a solution from this answer: https://ethereum.stackexchange.com/a/3614/264

Update

Since 0.4.17 you can use pragma experimental ABIEncoderV2 to return structs. Of course, until the experimental keyword is removed, it's not safe to use it in production apps.